home *** CD-ROM | disk | FTP | other *** search
/ A.C.E. 2 / ACE CD 2.iso / FILES / DOCS / AMOSDOC.LHA / AmosPart4.doc < prev    next >
Encoding:
Text File  |  1994-11-27  |  148.8 KB  |  4,352 lines

  1. 15: BACKGROUND GRAPHICS
  2.  
  3. Nowadays, it's not uncommon for an arcade game to contain hunderds of
  4. different screens. With compaction, it's possible to crap a single 32
  5. colour screen into about 30k of memory. So 100 screens would be the
  6. equivalent of about 3 Megabytes of data. Imagine how difficult this
  7. would be to fit into a standard A500!
  8.  
  9.   The classic way of avoiding this restriction, is to construct your
  10. backgrounds out of a set of simple building blocks. Once these "tiles"
  11. have been created, they can be placed on the screen in any order you
  12. like. So the same set of tiles can be reused to generate a vast number
  13. of potential screens. Each screen is now stored as a simple list of its
  14. components, and requires a tiny fraction of the original memory.
  15.  
  16.   In order to exploit this system, you'll obviously need some way of
  17. defining your various screen maps. As you might have guessed, we've
  18. helpfully provided you with a powerful map definer accessory on the
  19. AMOS program disc. Full details can be found in the accompanying
  20. documentation file.
  21.  
  22.   AMOS Basic also includes a number of special instructions for drawing
  23. your tiles on the screen. These make it easy to generate the fast
  24. scrolling backgrounds that are the hallmark of a modern arcade game.
  25.  
  26.  
  27. Icons
  28. =====
  29. Icons are separate images which have been especially designed for
  30. producing your background screens. Once you've drawn an icon, it's
  31. fixed permanently into place. So you can't move it to a new position
  32. using the AMAL animation system.
  33.  
  34.   All icons are stored in their own AMOS memory bank (#2). This bank is
  35. created using the Sprite definer accessory (on the AMOS Program disk),
  36. and will be automatically saved along with your Basic programs.
  37.  
  38.   Like Bobs, Icons are displayed using the Amiga's amazing Blitter
  39. chip. But since Icons are essentally static objects, they are usually
  40. drawn in REPLACE mode. Your icons will therefore totally erase any
  41. existing graphics at the current screen position.
  42.  
  43.  
  44.  
  45.                        PASTE ICON (draw an icon)
  46.  
  47. PASTE ICON x,y,n
  48.  
  49. Draws icon number n on the screen at GRAPHIC coordinates x,y. n is the
  50. number of the icon which is to be displayed. This must have been
  51. previously stored in the ICON bank.
  52.  
  53.   Icons can be freely positioned anywhere on the screen, subject to the
  54. normal clipping rules. Example:
  55.  
  56.         Load "AMOS_DATA:Icons/Map_icons.abk"
  57.         Screem Open 0,320,256,32,Lowres : Cls 0 : Get Icon Palette
  58.         For X=1 To 11 : Paste Icon X*32,0,1 : Next X
  59.         For Y=1 To 6 : Paste Icon 0,Y*32+11 : Paste Icon 288,Y*32,1
  60.         Next Y
  61.         For X=1 To 11 : Paste Icon X*32,223,1 : Next X
  62.  
  63. Note that if you're using double buffering, a copy of your icons will
  64. be drawn into both the physical and logical screens. Since this is
  65. rather slow, it's common practive to add a call to AUTOBACK 0 before
  66. drawing your icons on the screen. This restricts straight to the
  67. physical screen using SCREEN COPY, saving a considerable amount of
  68. time.
  69.  
  70.   For a further example, see the MAPVIEW program on the AMOS DATA disc.
  71. This displays a background screen you've created using the AMOS Map
  72. Editor.
  73.  
  74.  
  75.  
  76.                        GET ICON (create an icon)                           208
  77.  
  78. GET ICON [s,] i,tx,ty TO bx,by
  79.  
  80. Captures an image from the screen and loads it into icon "i". If this
  81. icon does not presently exist, it will be created for you in bank 2.
  82. This bank will be automatically reserved by the system if required.
  83.  
  84.   i is the number of your icon, starting from 1. tx,ty to bx,by define
  85. the rectangular zone which encloses the selected region.
  86.  
  87.   s determines the number of the screen which will be used as the
  88. source of your image. If it's omitted, the image will be taken from the
  89. current screen instead. Example:
  90.  
  91.         Erase 2
  92.         F$=Fsel$("*.*","","Load a screen") : If F$="" Then Direct
  93.         If Exist(f$) Then Load Iff f$,0 Else Direct
  94.         SH=Screen Height : H=SH/32-1 : SW=Screen Width : W=SW/32-1
  95.         For Y=0 to H
  96.           For X=0 to W
  97.             Get Icon X+Y*W+1,X*32,Y*32 To X*32+31,Y*32+31
  98.           Next X
  99.         Next Y
  100.         Cls 0
  101.         Do
  102.           Paste Icon Rnd(Sw-1),Rnd(SH-1),Rnd/(H*W)+1
  103.         Loop
  104.  
  105.  
  106.  
  107.                   GET ICON PALETTE (get icon colours)
  108.  
  109. GET ICON PALETTE
  110.  
  111. Grabs the colours of the icon images in bank 2, and loads them into the
  112. current screen palette. This command is normally used to initialize the
  113. screen after you'be loaded some icons from the disc. Example:
  114.  
  115.         Load "AMOS_DATA:Icons/Map_icons.abk"
  116.         Get Icon Palette
  117.         Paste Icon 100,100,1
  118.  
  119.  
  120.  
  121.                        DEL ICON (deletes icons)                            209
  122.  
  123. DEL ICON n[ TO m]
  124.  
  125. Deletes one or more icons from the icon bank. n is the number of the
  126. first icon to be removed.
  127.  
  128.   m is the optional number of the last icon to be deleted in the list.
  129. If it's included all the icons from first to last will be erased one
  130. after another.
  131.  
  132.   When the final icon in a bank has been deleted, the entire bank will
  133. be removed from memory.
  134.  
  135.  
  136.  
  137.             MAKE ICON MASK (set colour zero to transparent)
  138.  
  139. MAKE ICON MASK [n]
  140.  
  141. Normally, any icons you draw on the screen will completely replace the
  142. existing background. The icon will seem to be displayed in a
  143. rectangular box filled with colour zero.
  144.  
  145.   If you want to avoid this effect and overlay your icons directly over
  146. the current graphics, you'll need to create a *mask* for your icons.
  147. This informs AMOS that colour zero should be treated as transparent.
  148.  
  149.   n is the number of the icon to be affected. If it's omitted, a mask
  150. will be defined for all icons in the bank. See EXAMPLE 15.1
  151.  
  152.  
  153. Screen blocks
  154. =============
  155. AMOS Basic supplies you with a set of powerful BLOCK commands which
  156. allow you to grab part of an image into memory and paste it anywhere on
  157. the screen.
  158.  
  159.         These instructions are mainly used for holding temporary data,
  160. since your blocks cannot be saved along with your Basic programs.
  161.  
  162.   Blocks are especially effective in the construction of dialogue
  163. boxes, as they can be used to save the background areas before
  164. displaying your new graphics.
  165.  
  166.   They can also be exploited in puzzle games like Split Personalities.
  167. Each block can be loaded with a single section of your image. You can
  168. then jumble your pictures by rearranging the blocks on the screen with
  169. PUT BLOCK.
  170.  
  171.  
  172.  
  173.               GET BLOCK (grab a screen block into memory)
  174.  
  175. GET BLOCK n,tx,ty,w,h[,mask]
  176.  
  177. GET BLOCK grabs a rectangular area in block number n, starting at
  178. coordinates tx,ty.
  179.  
  180.   n is the number of the block ranging from 1-65535. tx, ty set the
  181. coordinates of the top left hand corner of your block. w,y hold the
  182. width and height of the block respectively.
  183.  
  184.   "mask" is a flag which chooses whether a mask will be created for
  185. your new block.
  186.  
  187.   mask=0        Replace mode. When the block is drawn on the screen,
  188.                 it will totally destroy any graphics at that current
  189.                 position.
  190.   mask=1        Calculates a mask for the block. Colour zero will now
  191.                 be treated as if it were transparent.
  192.  
  193.  
  194.  
  195.                 PUT BLOCK (copies a previously created                     210
  196.                         block onto the screen)
  197.  
  198. PUT BLOCK n[,x,y]
  199. PUT BLOCK n,x,y,planes[,minterms]
  200.  
  201. PUT BLOCK copies block number n to the current screen. x,y specify the
  202. position of your new block on the screen. If they are omitted the block
  203. will be redrawn at its original screen coordinates.
  204.  
  205.   Note that all drawing operations will be clipped to fit into the
  206. current screen, starting from the nearest 16 pixel boundary.
  207.  
  208.   For a demostration of the BLOCK commands see the routine in EXAMPLE
  209. 15.2. We've also provided experienced programmers with a couple of
  210. optional extras. These are not needed for the vast majority of
  211. applications, they're only required when you want to achieve weird
  212. special effects on the screen!
  213.  
  214.   "planes" holds a bit-map which sets the range of colours which will
  215. be drawn in your block. The Amiga's screen is divided up into segments
  216. known as bit-planes. Each plane contains a single bit for every point
  217. on the Amiga's screen. When the Amiga's hardware displays this point,
  218. it combines the bits from each plane to calculate the required colour
  219. number. Each bit in "planes" represents the status of a single
  220. bit-plane. If it's set to one, then the selected plane will be drawn by
  221. the instruction, otherwise it will be completely ignored. The first
  222. plane is represented by bit zero, the second by bit one, etc.
  223.  
  224.   Usually, the block will be displayed in all the available bit-planes.
  225. The corresponds to a bit-pattern of %111111
  226.  
  227.   "minterm" selects the blitter mode used to copy your block on the
  228. screen. A full description of the possible drawing modes can be found
  229. in the section on SCREEN COPY. The best way to loearn about these
  230. options is to experiment!
  231.  
  232.  
  233.  
  234.                    DEL BLOCK (delete a screen block)
  235.  
  236. DEL BLOCK n
  237.  
  238. Deletes one or more blocks and restores the memory used to AMOS Basic.
  239.  
  240. DEL BLOCK       Erases *all* current blocks
  241. DEL BLOCK n     Deletes block number n.
  242.  
  243.  
  244.  
  245.              GET CBLOCK (save and compact a screen image)                  211
  246.  
  247. GET BLOCK n,x,y,sx,sy
  248.  
  249. The GET BLOCK command saves and compacts a rectangular area of the
  250. screen. The compaction system used by this command has been especially
  251. optimized for speed. So it's nowhere near as efficient as the dedicated
  252. AMOS compression routines provided by the PACK or SPACK instructions.
  253.  
  254.   CBLOCKS are often used to grab the area underneath your dialogue
  255. boxes. After the dialogue has been completed, the screen can quickly
  256. restored back to its original state. See EXAMPLE 15.3.
  257.  
  258.   n specifies the number of your block and can range between 1-65535.
  259.  
  260.   x,y are the top left coordinates. The x coordinate is rouded to the
  261. nearest multiple of 8.
  262.  
  263.   w,h hold the dimensios of the area to be saved. The width is always
  264. rounded to an exact multiple of 8.
  265.  
  266.  
  267.  
  268.                      PUT CBLOCK (displays a block
  269.                          created using CBLOCK)
  270.  
  271. PUT CBLOCK n [,x,y]
  272.  
  273. Places block n on the current screen at coordinates x,y. If the target
  274. coordinates are omitted, the block will be redrawn at its original
  275. screen position. Also note that x is automatically rounded to the
  276. nearest eight pixel boundary.
  277.  
  278.  
  279.  
  280.                   DEL CBLOCK (deletes a screen block
  281.                        defined with GET CBLOCK)
  282.  
  283. DEL CBLOCK [n]
  284.  
  285. Erases all blocks from memory. If n is present only block n will be
  286. deleted.
  287.  
  288.  
  289.  
  290.  
  291.  
  292.  
  293.  
  294.                                16: MENUS                                   212
  295.                       ---------------------------
  296.  
  297. If you've used the Amiga for some time you'll already be familiar with
  298. the idea of menus. Impossible as it seems, AMOS has taken the existing
  299. system and improved it almost beyond recognition.
  300.  
  301.   Menus can be created with up to eight separate levels, and each
  302. individual menu item can be repositioned on the screen at will. Menu
  303. titles can be printed in any combination of colours or styles. You can
  304. also include bobs or icons directly in your menus using an amazing menu
  305. definition language.
  306.  
  307.   AMOS Basic is equally impressive when it comes to reading a menu.
  308. There's a buit-in interrupt-dricen ON MENU command which can
  309. automatically branch to a selected point in your program depending on
  310. the option selected. Furthermore, any menu option can be accessed
  311. directly from the keyboard using the MENU KEY instruction.
  312.  
  313.   For a demonstration of the terrific effects that can be achieved with
  314. this system, load the program EXAMPLE 16.1.
  315.  
  316.  
  317. Using a menu
  318. ============
  319. All AMOS menus are called up by holding down the right mouse button in
  320. the standard way. Once a menu has been activated you can then select an
  321. option directly with the mouse cursor. When you release the button, the
  322. option number you have chosen will be returned to your program.
  323.  
  324.   Menus can be repositioned by placing the mouse cursor over the top
  325. left corner of an item and holding down the LEFT button. A small box
  326. will now appear on the menu bar which can be dragged across the screen
  327. using the mouse.
  328.  
  329.   In addition, holding down the SHIFT key will freeze a menu into
  330. place. This allows you explore a menu without selecting any of the
  331. various options. You can also use any of the mouse features such as
  332. slowing or axis selection in conjunction with your menus.
  333.  
  334.  
  335. Creating a simple menu
  336. ======================
  337. AMOS menus can be created either directly within your programs or using
  338. a special menu definer included on the AMOS program disc.
  339.  
  340.   If you've never used menus before, the sheer variety of the available
  341. menu commands may seem a little overwhelming. Here's a brief
  342. description of the basic features to provide you with a painless
  343. introduction to AMOS menus.
  344.  
  345.  
  346. Setting the title line
  347. ----------------------
  348. The first stage in the creation of a menu is to define the "title
  349. line". THe title line of a menu can be set using the MENU$ command. In
  350. its simplest form this has the format:
  351.  
  352.  
  353.  
  354.                        MENU$ (set a menu title)
  355.  
  356. MENU$(n)=title$
  357.  
  358. MENU$ creates a title line for your menu. Each heading is assigned it's
  359. own individual number starting from one, and increasing from left to
  360. right. So the leftmost title is repsresented by a one, the next title
  361. as two, etc.
  362.  
  363.   The text in "title$" holds the name of the option which will be
  364. displayed in your new menu. Here is a simple example which constructs a
  365. menu line consisting of just two titles: ACTION and MOUSE
  366.  
  367.         Menu$(1)=" Action "
  368.         Menu$(2)=" Mouse "
  369.  
  370. Note the space after "Action" - this will separate it from Mouse, the
  371. next menu along. You must now specify a list of options to be              213
  372. associated with each of your new headings. These form a vertical bar
  373. which will drop into place whenever a title is selected with the mouse.
  374.  
  375.  
  376.  
  377.                     MENU$(t,o)  (set a menu option)
  378.  
  379. MENU$(t,o)=option$
  380.  
  381. This second form of MENU$ defines a set of options which will be
  382. displayed in the menu bar.
  383.  
  384.   t is the number of menu heading which your option will displayed
  385. under. o is the option number you with to install in the menu bar.
  386. All options are numbered downwards from the top of the menu, starting
  387. from one.
  388.  
  389.   The only physical limit to the size of your menu is the amount of
  390. memory, but it's wise to restrict yourself to less than about 10
  391. options for each title. This will keep the complexity of your menus
  392. down to an agreeable minimum.
  393.  
  394.   "option$" holds the name of your new option. This can consist of any
  395. section of text you like. For an example, try adding the following
  396. lines to the program above:
  397.  
  398.         Rem Action menu
  399.         Menu$(1,1)=" Quit "
  400.         Rem Mouse menu
  401.         Menu$(2,1)=" Arrow "
  402.         Menu$(2,2)=" Pointer "
  403.         Menu$(2,3)=" Clock "
  404.         Wait Key
  405.  
  406. This specifies a list of alternatives for the ACTION and the mouse
  407. menus. If you try to run this program as it stands, nothing will
  408. happen. That's because the menus need to be initialised with a call to
  409. the MENU ON command. Enter this thin above program before the Wait Key
  410. instruction. Now run the example and select the menu items with the
  411. mouse cursor. Remember to hold down the RIGHT mouse button first!
  412.  
  413.  
  414.  
  415.                         MENU ON (activate menu)
  416.  
  417. MENU ON
  418.  
  419. Activates a menu defined using the MENU$ command. The menu line will
  420. now appear automatically when the right mouse button is pressed ny the
  421. user. To start the previous menu, insert the following line after the
  422. definition statements.
  423.  
  424.         Menu On
  425.  
  426. Go to the Direct window and play around with the menus. Select options     214
  427. by pressing the right mouse button
  428.  
  429.  
  430. Reading a simple menu
  431. =====================
  432. Once you've created your menu and activated the AMOS menuing system
  433. you'll want to discover which options have been selected by the user.
  434. This can be accomplished using a simple form of the CHOICE command.
  435.  
  436.  
  437.  
  438.                          =CHOICE (read a menu)
  439.  
  440. selected=CHOICE
  441.  
  442. CHOICE returns a value of -1 (true) if the menu has been highlighted by
  443. the user, otherwise 0. It's automatically reset to 0 after each test.
  444. It's also possible to find the title number which has been selected
  445. using a second form of this instruction.
  446.  
  447. heagind=CHOICE(1)
  448.  
  449. "heading" now contains the number of the "title" which has been
  450. highlighted by the user. Similarly you can retrieve the actual option
  451. number which has been chosen with a parameter of two.
  452.  
  453. item=CHOICE(2)
  454.  
  455. Try adding the following lines to the previous example:
  456.  
  457.         Do
  458.           Rem If choice=-1 can be simplified to: If choice, as seen...
  459.           If choice and choice(1)=1 Then Exit
  460.           If choice(1)=2 and choice(2)<>0 Then Change Mouse choice(2)
  461.         Loop
  462.  
  463. This changes the shape of the mouse cursor depending on which option
  464. you have chosen from the menu. A full demonstration of these menu can
  465. be found in the file EXAMPLE 16.2.
  466.  
  467.  
  468. Advanced menuing features
  469. -------------------------
  470. We will now cover some of the more advanced menuing features available
  471. from within AMOS Basic. Used properly these AMOS menus can add a whole
  472. new dimension to your programs.
  473.  
  474.  
  475.  
  476.  
  477.                          MENU$ (create a menu)                             215
  478.  
  479. MENU$(,,)=normal$[,selected$][,inactive$][,background$]
  480.  
  481. Defines the appearance of each individual menu item in one of your
  482. menus. Unlike normal Amiga menus these items are not restricted to
  483. standard text. They can also include embedded commands which allow you
  484. to draw bobs, icons or graphics at any point in the menu line.
  485.  
  486.   Any of the parameters in this instruction may be optionally omitted,
  487. so you can change parts of a menu description indenpendently. A value
  488. of "" in your menu string will ERASE the existing setting. Similarly
  489. you can retain the original value by including a comma at the
  490. appropriate point. For example:
  491.  
  492.         Menu$(1)=" Action ","" : Rem Erase second option
  493.         Menu$(2)=" Mouse 2 ",, : Rem Change title without altering
  494.                                      anything else.
  495.  
  496. The position of the menu item within the actual menu is indicated using
  497. a list of up to eight parameters separated by commas. The general
  498. format is:
  499.  
  500.         (item)/(item,option)/(item,option,sub option)...
  501.  
  502. "normal$" is a string which sets the normal appearance of an item when
  503. it's displayed in the menu. "selected$" changes the effect of
  504. highlighting a menu option with the mouse. As a default, selected items
  505. are printed in inverse text.
  506.  
  507.   "inactive$" changes the appearance of an item which has been
  508. deactivated using the MENU INACTIVE command. If this string is omitted,
  509. all inactive imtes will be displayed in italics. "background$" creates
  510. a background for your menu items when they are initially drawn.
  511. Generally this will be a bo of some sort created with the internal Bar
  512. or line commads.
  513.  
  514.   For now one, we'll abbreviate these parameters using a standard
  515. notation:
  516.  
  517.         setting$=[,selected$][,inactive$][,background$]
  518.  
  519.  
  520. The menu hierarchy
  521. ------------------
  522. The level of an item in the menu is determined by its position in the
  523. menu hierarchy.
  524.  
  525.         Menu$(1)="Title"
  526.         Menu$(1,1)="Option 1"
  527.         Menu$(1,2)="Option 2"
  528.         Menu$(1,2,1)="Item 1"
  529.  
  530. This defines a simple menu. The structure of a menu is similar to that
  531. of an array. Each level of the menu is represented by its own dimension
  532. in the array, and is controlled using a separate version of the MENU$
  533. command.
  534.  
  535.   The first level represents the title line which appears at the top of
  536. your menus. It can be set using a command like:
  537.  
  538.         Menu$(n)=title$[setting$]
  539.  
  540. "n" now corresponds to the position of the title from the left of the      216
  541. screen, and setting$ refers to the three optional strings which define
  542. the general appearance of the menu. It's important to define the title
  543. of your menus first as this *dimensions* the array. All other items may
  544. be created in any order you wish.
  545.  
  546.   Each title is associated with a list of menu options which drop into
  547. view when the menu is selected. These form the second level of the menu
  548. structure and are defined using a second version of the MENU$ command.
  549.  
  550.         Menu$(n,option)=Item$[setting$]
  551.  
  552. "option" holds the number of the item measured from the top left of the
  553. menu bar. There's no limit to the number of options which may be linked
  554. to a single title, other than the amount of available memory.
  555.  
  556.   Each individual option can in turn be associated with its own sub
  557. menus up to a total of eight levels.
  558.  
  559.         Menu$(n,option,sub option)=Item$[setting$]
  560.  
  561. Once you've created a menu it can be expanded or changed at any point
  562. in your program. Never change the current screen while you are creating
  563. a menu as this will lead to an error message.
  564.  
  565. See EXAMPLE 16.3
  566.  
  567.  
  568.  
  569.                           =CHOICE (read menu)
  570.  
  571. item=CHOICE[(dimension)]
  572.  
  573. The CHOICE function checks whether an option has been highlighted on
  574. the current menu. If an item has been selected (down to the lowest
  575. level), CHOICE will return a value of -1, otherwise it will be 0. After
  576. you've called this function, the status of the menu will be
  577. automatically restored to 0 (false). This stops a single menu access
  578. from being accidentally detected several times.
  579.  
  580.   The second form of this command returns the option selected at the
  581. required level.
  582.  
  583. item=CHOICE(dimension)
  584.  
  585. "dimension" indicates the level of the menu which is to be read. As you
  586. may recall, a level number of 1 corresponds to the title line of the
  587. menu. Similartly the levels between 2 and 8 indicate the number of an
  588. ioption which has been chosen. If a menu item has not been selected,
  589. "item" will be loaded with a value of zero. For example:
  590.  
  591.         Menu$(1)="Menu"
  592.         Menu$(1,1)="Option 1"
  593.         Menu$(1,2)="Option 2"
  594.         Menu$(1,2,1)="Option 2.1"
  595.         Menu On
  596.         Do
  597.           If choice Then Print choice(1),choice(2),choice(3)
  598.         Loop
  599.  
  600. If you wanted to implement larger menus with this system, your program
  601. would need to use a long list of IF...THEN statements to deal with each
  602. and every possibility. This would cause a small but significant delay
  603. in your program while the menus were being read. It would also make it
  604. very difficult to amend your program later. Fortunately AMOS Basic
  605. provides you with a painless method of managing even the largest menus.
  606.  
  607.  
  608.  
  609.                 ON MENU PROC (automatic menu selection)                    217
  610.  
  611. ON MENU PROC proc1 [,proc2,...]
  612.  
  613. Each title in your menu can be assigned its own procedure which will be
  614. executed automatically whenever an option is selected by the user. The
  615. action of this command is similar to the code below:
  616.  
  617.         If Choice
  618.           If Choice(1)=1
  619.             Proc1
  620.           Endif
  621.           If Choice(1)=2
  622.             Proc2
  623.           Endif
  624.         :  :  :
  625.         :  :  :
  626.         Endif
  627.  
  628. There is one crucial difference between the ON MENU command and the
  629. above instructions. ON MENU is performed 50 times a second using
  630. interrupts and does not affect the overall running of your program.
  631. This means that your program can be doing something totally different
  632. while the menus are being checked by the system.
  633.  
  634. Whenever the user selects a menu item the required procedure will be
  635. immediately executed with no further ation on the part of your program.
  636. Your procedure can then use the CHOICE command to find which option has
  637. been chosen and perform the appropriate action.
  638.  
  639.   After the procedure has concluded, your program will be returned to
  640. the instruction following the ON MENU call. Here's an example:
  641.  
  642.         Menu$(1)="Action" : Menu$(1,1)="Count" : Menu$(1,2)="Quit"
  643.         Menu On : Rem Activate menu
  644.         On Menu Proc ACTION
  645.         On Menu On : Rem Activate On Menu command
  646.         Do
  647.           X$=Inkey$ : If X$<>"" Then Print X$;: Inc W
  648.         Loop
  649.         Procedure ACTION                                                   218
  650.           Shared W
  651.           If Choice(2)=1
  652.             Locate 0,0 : Print "You typed ";W;" letters" : W=0
  653.             On Menu On : Rem Initialise menus
  654.           Endif
  655.           If Choice(2)=2 Then Edit
  656.         End Proc
  657.  
  658. There are a couple of important points to note about this example.
  659. Firstly, see how the on menu sequence is activated using the ON MENU ON
  660. command. This *must* be called after the menu handling procedure has
  661. finished as it's needed to restart the menuing system. Also note the
  662. use of INKEY$ rather than INPUT. The INPUT command will halt the menu
  663. checks while you are entering a line. All other commands can be used
  664. without problems, including WAIT, WAIT VBL and WAIT KEY. For a further
  665. example see EXAMPLE 16.4
  666.  
  667.  
  668.  
  669.                ON MENU GOSUB (automatic menu selection)
  670.  
  671. ON MENU GOSUB label1 [,label2,...]
  672.  
  673. Enters one of a list of subroutines depending on the option which has
  674. been selected by the user. Once you've called this command and created
  675. your subroutines, the menus will be checked automatically 50 times a
  676. second.
  677.  
  678.   Note that each title on the menu line is handled by its own
  679. individual subroutine. This differs from its AMIGA Basic equivalent
  680. which controls the entire menu with just a single routine.
  681.  
  682.   After using this command you should activate the menuing system with
  683. a call to the ON MENU. The menus must be reinitialised in this way
  684. before jumping back to the main program with RETURN. Also note that
  685. label *MAY NOT* be replaced by an expression as the label will only be
  686. evaluated once when the program is run.
  687.  
  688.  
  689.  
  690.                 ON MENU GOTO (automatic menu selection)
  691.  
  692. ON MENU GOTO label1 [,label2,...]
  693.  
  694. This command has now been superceded by the more powerful ON MENU PROC
  695. and ON MENU GOSUB instructions. It's intended to provide compability
  696. with programs written in STOS Basic. WHen ever a menu is selected, the
  697. program wlil jump to the appropriate label.
  698.  
  699.  
  700.  
  701.                 ON MENU ON/OFF ([de]activate automatic
  702.                             menu selection)
  703. ON MENU ON
  704.  
  705. Activates the automatic menuing system created by the ON MENU
  706. PROC/GOSUB/GOTO commands. After a sub-routine has been accessed in this
  707. way, the system will be DISABLED. So it's vital to reactivate the
  708. system with ON MENU ON before returning to the main program.
  709.  
  710. ON MENU OFF
  711.  
  712. This temporarily freezes the automatic menuing system. It's useful when
  713. your program is executing a procedure which needs to be performed
  714. without interruptions - such as loading and saving information to the
  715. disc. The menus can be reactivated using ON MENU ON.
  716.  
  717.  
  718.  
  719.             ON MENU DEL (dlete the labels used by ON MENU)                 219
  720.  
  721. ON MENU DEL
  722.  
  723. This erases the internal list of labels or procedures created by the ON
  724. MENU commands. You can now redirect your menus to another part of your
  725. program using a further call to ON MENU. WARNING! Only use this command
  726. after you've deactivated the menus with ON MENU OFF.
  727.  
  728.  
  729. Keyboard shortcurs
  730. ------------------
  731. Despite the undoubted appeal of menus, some users prefer to call up the
  732. options of a program straight from the keyboard. Althought menus are
  733. certainly easy for beginners, once you've familiarised yourself with a
  734. program it can be much faster to call up an option from the keyboard.
  735.  
  736.   AMOS Basic allows you to assign a keyboard shortcut to any of your
  737. menu items. These keystrokes are interpreted exactly as if the user had
  738. accessed the equivalent option from the menu. They can be used with any
  739. of the AMOS Basic menuing commands, including ON MENU.
  740.  
  741.  
  742.  
  743.                 MENU KEY (assign a key to a menu item)
  744.  
  745. MENU KEY(,,) TO c$
  746. MENU KEY(,,) TO scan[,shift]
  747.  
  748. This allows you to assign any key to any item in a previously defined
  749. menu. The only restriction is that item you have specified must be at
  750. the bottom level of our menu. So you can't use a shortcut to select a
  751. sub menu as each command must correspond to a single option in the
  752. menu.
  753.  
  754.   c$ is a string containing a single character which is to be assigned
  755. to the menu option. Any additional characters in the string will be
  756. ignored.
  757.  
  758.   Each key on the Amiga's keyboard is assigned its own individual
  759. scancode. By using this code you can assign keys to a menu which have
  760. no Ascii equivalents. Here is a list of scancodes which can be used
  761. with your menus.
  762.  
  763.         Scancode  Keys
  764.         --------  ----
  765.         80 - 89   Function keys F1-F10
  766.            95     Help
  767.            69     Esc
  768.  
  769. "shift" is an optional bitmap which allows you to check for control key    220
  770. combinations such as ALT+HELP or CONTROL+D. The format of "shift" is:
  771.  
  772.         Bit  Key Tested      Notes
  773.         ---  ----------      -----
  774.          0   Left SHIFT      Only one shift key can be tested at a time
  775.          1   Right SHIFT
  776.          2   Caps Lock       Either ON or OFF
  777.          3   CTRL
  778.          4   Left ALT
  779.          5   Right ALT
  780.          6   Left AMIGA      C= key on some keyboards
  781.          7   Right AMIGA
  782.  
  783. Note that if you set more than a single bit in this pattern, you'll
  784. have to press several keys simultaneously to call up your menu item.
  785. Any of these short-cuts can be deactivated by using MENU KEY with no
  786. parameters. For example:
  787.  
  788.         Menu Key(1,10)
  789.  
  790. With the help of MENU KEY command, adding shortcuts to a menu is a
  791. trivial operation, so you are strongly recommended to include them as
  792. standard in your programs. Here is an example that checks for the
  793. Amiga's 10 function keys:
  794.  
  795.         Menu$(1)=" Function Keys "
  796.         For A=1 To 10
  797.           OPT$=" F"+Str$(A)+" "
  798.           Menu$(1,A)=OPT$
  799.           Menu Key(1,A) To 79+A
  800.         Next A
  801.         Menu On
  802.         Do
  803.           If Choice Then Print "You pressed function key ";Choice(2)
  804.         Loop
  805.  
  806.  
  807. Menu control commands
  808. ---------------------
  809.  
  810.  
  811.                        MENU ON (activate a menu)
  812.  
  813. MENU ON [bank]
  814.  
  815. Activates a menu which has been previously defined in your program. The
  816. menu will be displayed when the user next presses the right mouse
  817. button, and the options can be selected in the usual way. If a "bank"
  818. number is included with the instruction, then the menu will be taken
  819. from the appropriate memory bank. See MAKE MENU BANK for more details.
  820.  
  821.  
  822.  
  823.                MENU OFF (temporarily deactivate a menu)                    221
  824.  
  825. MENU OFF
  826.  
  827. THis is the opposite of the MENU ON command. It temporarily freezes the
  828. action of the entire menu. The menu can be restared at any time using
  829. the MENU ON command.
  830.  
  831.  
  832.  
  833.                MENU DEL (delete one or more menu items)
  834.  
  835. Erases the selected menu from the Amiga's memory and restores the space
  836. to the rest of your program. There are two possible formats.
  837.  
  838. MENU DEL
  839.  
  840. Erases the enitre menu. WARNING! This command is irrevocable!
  841.  
  842. MENU DEL(,,)
  843.  
  844. Deletes just a section of the menu. The (,,) parameters contain a list
  845. up to eight values separated by commas. These indicate the precise
  846. position of the item in the menu hierarchy. For example:
  847.  
  848.         Menu Del(1) : Rem Erase title number 1
  849.         Menu Del(1,2) : Rem Erase option 2 of title 1
  850.  
  851.  
  852.  
  853.                 MENU TO BANK (save the menu definitions
  854.                            in a memory bank)
  855.  
  856. MENU TO BANK n
  857.  
  858. This instruction allows you to save an entire menu tree into memory
  859. bank n. If bank n already exist, you'll get a "bank already reserved"
  860. error.
  861.  
  862.   Once you've stored a menu in this way, it will be saved automatically
  863. along with your Basic program. By storing your menu definitions in a
  864. memory bank, you can reduce the size of your program listings
  865. significantly. This will free valuable space in the editors memory, and
  866. will allow you to write longer Basic programs using exactly the same
  867. amount of memory.
  868.  
  869.  
  870.  
  871.                BANK TO MENU (restores a menu definition
  872.                          saved in a menu bank)
  873.  
  874. BANK TO MENU n
  875.  
  876. Sets up a menu definition from menu data stored in bank number n. You
  877. menu will be restored to exactly the same state as it was originally
  878. saved. If the menu is complex, this process may take a little time. To
  879. activate your ne menu call the MENU ON instruction.
  880.  
  881.  
  882.  
  883.                     MENU CALC (recalculate a menu)                         222
  884.  
  885. MENU CALC
  886.  
  887. One of the nicest features of AMOS menus is that they can be easily
  888. changed during the course of a program. After you've created your
  889. initial definition you can add new items and replace existing options
  890. as well.
  891.  
  892.   Al your menu items are automatically repositioned when the menu is
  893. selected with the right mouse button. If your menus are extremely large
  894. this may takek a little time. MENU CALC allows you to perform this
  895. process at the most appropriate point in your program, and avoid
  896. unnecessary and unwanted delays.
  897.  
  898.   Note that in order to stop the user calling the menu while it's being
  899. changed, you are strongly adviced to freeze the menus with MENU OFF at
  900. the start of your procedure. The menu can then be safely restarted
  901. using the MENU ON command after you've finished. Evolving menus are
  902. particularly useful for adventure games as each location can have its
  903. own individul menu options which can be updated depending on the
  904. player's actions.
  905.  
  906.  
  907.  
  908. Embedded menu commands
  909. ======================
  910. Any menu string can optionally include a powerful set of embedded
  911. commands which allow you to customize the appearance of your menus to
  912. an incredible degree. The list of commands in enclosed between sets of
  913. round brackets () and individual instructions are separated using
  914. colons ":". For example:
  915.  
  916.         Menu$(1)="(Locate 10,10 : Ink 1,1) Hello"
  917.  
  918. Each instruction consists of just two characters which can be in either
  919. upper or lower case. Anything else will be ingnored completely. Most
  920. commands also require you to input one or more commands. These numbers
  921. *must never* make use of expressions as these are not evaluated. The
  922. commands are listed below.
  923.  
  924.   Note: In the syntax the two important characters which make up the
  925. command are in upper case and highlighted bold.
  926.  
  927.  
  928.  
  929.                            BOB (draw a bob)
  930.  
  931. BOb n
  932. --
  933. The BOB command draws a bob number n at the current cursor position. No
  934. accound is taken of the hot spot of the bob. All coordinates are
  935. measured relative to the top left corner. Also note that colour zero is
  936. usually treated as transparent. This may be changed using the NOMASK
  937. command from AMOS Basic. For example:
  938.  
  939.         Load "AMOS_DATA:Sprites/Octopus.abk"
  940.         Menu$(1)="(Bob 1) 1":Menu$(1,1)="(Bob 2) 2"
  941.         Menu$(1,2)="(Bob 3) 3"
  942.         Menu On : Wait Key
  943.  
  944.  
  945.  
  946.                           ICON (draw an icon)
  947.  
  948. ICon n
  949. --
  950. Draws icon # n at the current cursor position. Note that unlike bobs,
  951. colour zero is NOT normally transparent. See the Basic MAKE ICON MASK
  952. for more details.
  953.  
  954.  
  955.  
  956.                    LOCATE (move the graphics cursor)                       223
  957.  
  958. LOcate x,y
  959. --
  960. Tis command moves the graphics cursor to coordinates x,y measured
  961. relative to the top left corner of the menu line. Note that after an
  962. instruction the graphics cursor will always be positioned at the bottom
  963. right of the object which has just been drawn. These coordinates will
  964. also be used to determine the location of any further items in your
  965. menu like so:
  966.  
  967.         Menu$(1)="Example ":Menu$(1,1)="Locate (Lo 50,50) in action "
  968.         Menu$(1,2)="Guess my coords"
  969.         Menu On : Wait Key
  970.  
  971.  
  972.  
  973.                     INK (set Ink and Paper colours)
  974.  
  975. INk n,value
  976. --
  977. The INK command assigns the colour indexes to be used for the PEN,
  978. PAPER and OUTLINE colours, Here's a list of the various possibilities:
  979.  
  980.         n       Effect
  981.         -       ------
  982.         1       Set text PEN colour
  983.         2       Set PAPER colour
  984.         3       Set OUTLINE colour
  985.  
  986.  
  987.  
  988.                            SFONT (set font)
  989.  
  990. SFont n
  991. --
  992. SFont sets the current font to *graphics* font number n. This will be
  993. used in all future menu items. NOte that you MUST call GET FONTS before
  994. this instruction is executed, otherwise it can only use the two rom
  995. fonts. See EXAMPLE 16.5.
  996.  
  997.  
  998.  
  999.                         SSTYLE (set font style)
  1000.  
  1001. SStyle n
  1002. --
  1003. This command sets the style of the current font to n which is a
  1004. bit-pattern in the following format:
  1005.  
  1006.         Bit    Effect
  1007.         ---    ------
  1008.          0     Underline
  1009.          1     Bold
  1010.          2     Italic
  1011.  
  1012.  
  1013.  
  1014.                           LINE (draw a line)                               224
  1015.  
  1016. LIne x,y
  1017. --
  1018. The LINE command draws a line from the current cursor position to the
  1019. graphics coordinates x,y. See EXAMPLE 16.6
  1020.  
  1021.  
  1022.  
  1023.                        SLINE (set line pattern)
  1024.  
  1025. SLine p
  1026. --
  1027. Sets the line style used in all subsequent LINE comands to the bit
  1028. pattern held in p. Since there is no expession evaluation, this pattern
  1029. should always be converted into decimal notation before use. A simple
  1030. demonstration of the possible line styles can be found in EXAMPLE 16.7.
  1031.  
  1032.  
  1033.  
  1034.                            BAR (draw a bar)
  1035.  
  1036. BAr x,y
  1037. --
  1038. This draws a rectangular bar from the current cursor coordinates to
  1039. x,y. See EXAMPLE 16.8.
  1040.  
  1041.  
  1042.  
  1043.                  OUTLINE (enclose bar with an outline)
  1044.  
  1045. OUtline flag
  1046. --
  1047. Draws a border in the current outline colour (ink 3) around all
  1048. subsequent bars. A value of one activates the border and 0 removes it.
  1049.  
  1050.  
  1051.  
  1052.                        ELLIPSE (draw an ellipse)
  1053.  
  1054. ELlipse r1,r2
  1055. --
  1056. Draws an oval with radii r1 and r2 at the current cursor coordinates.
  1057. To draw a circle, set r1 equal to r2. See example 16.9.
  1058.  
  1059.  
  1060.  
  1061.                         PROC (call a procedure)                            225
  1062.  
  1063. PRoc NAME
  1064. --
  1065. The PROC instruction allows you to call any AMOS Basic procedure
  1066. directly within a menu line. The called procedure must NOT include
  1067. paramters, otherwise a syntax error will be indicated.
  1068.  
  1069.   This command allows you to customize the menu precisely to your own
  1070. needs without having to limit yourself to the available menu commands.
  1071. In order to exploit these features, you'll need to understand a little
  1072. bit of theory.
  1073.  
  1074.   At the start of your procedure the following values are held in the
  1075. 68000's processor registers.
  1076.  
  1077.         Dreg(0)         X-Coord
  1078.  
  1079.   This holds the graphical X coordinate of the top left corner of the
  1080.   current menu item. Don't draw your gfxs over the part of the screen
  1081.   to the left of this point as this will confuse the menu redrawing
  1082.   process and may lead to unwanted effects.
  1083.  
  1084.         Dreg(1)         Y-Coord
  1085.  
  1086.   Contains the Y coordinate of your menu item. As with the X coordinate
  1087.   you should always limit your drawing operations to the region below
  1088.   this point to avoit possible errors.
  1089.  
  1090.         Dreg(2)         Status of drawing operations
  1091.  
  1092.   This register holds the current status of the menu operations. If it
  1093.   contains a value of 0 (false) the menu item is being drawn. In this
  1094.   case you will need to load Dreg(0) and Dreg(1) with the coordinates
  1095.   of the bottom right corner of your menu zone and return from the
  1096.   procedure immediately. If Dreg(0) is -1 (true) you are free to
  1097.   perform your gfx operations used by your procedure. After you have
  1098.   finished you should return the coordinates of the bottom right corner
  1099.   of your item in Dreg(0) and Dreg(1) as before.
  1100.  
  1101.         Dreg(3)         Status of menu item
  1102.  
  1103.   D3 is loaded with a value of -1 if the menu is highlighted and the
  1104.   first menu string is displayed, otherwise it will contain a value 0.
  1105.  
  1106.         Dreg(4)
  1107.  
  1108.   D4 is set to TRUE when the menu branch is initially opened.
  1109.  
  1110.         Areg(1)         Address of reserved zone
  1111.  
  1112.   This is the address of the zone created with RESERVE. It's used to       226
  1113.   allow several procedures to communicate with each other. See RESERVE
  1114.   for more details.
  1115.  
  1116.  
  1117.   The general structure of a menu procedure is:
  1118.  
  1119.         Procedure ITEM
  1120.           If DREG(2)
  1121.             X=DREG():Y=DREG(1)
  1122.              ...draw the item...
  1123.           Endif
  1124.           DREG(0)=BX
  1125.           DREG(1)=BY
  1126.         End Proc
  1127.  
  1128. The dimensions of the menu item as displayed on the screen are set
  1129. using the coordinates BX and BY. These MUST be loaded into registers D0
  1130. and D1 before leaving your procedure as they are needed to create the
  1131. final menu bar.
  1132.  
  1133.   While inside your procedure you can perform most AMOS instructions
  1134. including other procedures. But some instructions are absolutely
  1135. forbidden! If you use these commands, you won't get an error message
  1136. but your AMIGA may crash unexpectedly!
  1137.  
  1138.  * NEVER change the current screen inside a menu.
  1139.  * Don't set or reset a screen zone
  1140.  * Avoid using instructions such as WAIT, WAIT KEY, INPUT or INKEY$
  1141.  * Disc operations are absolutely forbidden!
  1142.  * Any error trapping in your procedure will be ignored.
  1143.  
  1144.   Used with caution, the PROC command can procedure some mind-blowing
  1145. effects. For a demonstration, load EXAMPLE 16.10.
  1146.  
  1147.  
  1148.  
  1149.                      RESERVE (reserve a local data
  1150.                          area for a procedure)
  1151. REserve n
  1152. --
  1153. Reserves n bytes of memory for this menu item. This area can be
  1154. accessed from within your menu procedure using the address held in
  1155. AREG(1). The data area you have created is common to all the strings in
  1156. the current menu object. It can be used to exchange parameters between
  1157. the various procedures called by a menu item.
  1158.  
  1159.  
  1160.  
  1161.              MENU CALLED (redraw a menu item continually)
  1162.  
  1163. MENU CALLED(,,)
  1164.  
  1165. Automatically redraws the selected menu item 50 times a second whenever
  1166. it's displayed on the screen. It's usually used in conjunction with a
  1167. menu procedure to generate animated menu items which change in front of    227
  1168. your eyes.
  1169.  
  1170.   In order to make use of this function, you first need to define a
  1171. menu procedure, using the principles outlined above. Then add a call to
  1172. this procedure in the required title strings using an embedded
  1173. MENU CALL. When the user displays the chosen item, your procedure will
  1174. be repeatedly accessed by the menuing system.
  1175.  
  1176.   Since your procedure will be called 50 times a second, it should
  1177. obviously return back to the menu as quickly as possible. This will
  1178. allow enough time for the rest of the menu to be succesfully updated.
  1179.  
  1180.   Also note that your embedded procedure can safely animate your item
  1181. using either bobs or sprites. However, as the menu items are NOT double
  1182. buffered, your bobs may flicker slightly on the screen. So it may be
  1183. better to use computed sprites for this purpose instead. Another
  1184. approach is to draw your display with the standard AMOS graphics
  1185. commands. An example of this can be seen in EXAMPLE 16.11.
  1186.  
  1187.  
  1188.  
  1189.                MENU ONCE (turns off automatic redrawing)
  1190.  
  1191. MEUN ONCE(,,)
  1192.  
  1193. Turns off the automatic updating system started using the MENU CALLED.
  1194.  
  1195.  
  1196. Alternative menu styles
  1197. =======================
  1198. Normally the titles of a menu are displayed as a horizontal line and
  1199. the options are arranged below it in a vertical menu bar. If you want
  1200. to create something a little unusual, you can change the format of each
  1201. level of your menu using the following three instructions:
  1202.  
  1203.  
  1204.  
  1205.                        MENU LINE (display a menu
  1206.                     as a horizontal line of items)
  1207. MENU LINE level
  1208. MENU LINE(,,)
  1209.  
  1210. Displays the menu options at the requested level in the form of a
  1211. horizontal line. This menu line starts from the left-hand corner of the
  1212. first title and stretches to the bottom right corner of the last.
  1213.  
  1214. MENU LINE level
  1215.  
  1216. Defines the menu style of an entire level of your menu. This sould only
  1217. be called during your menu definitions.
  1218.  
  1219. MENU LINE (,,)
  1220.  
  1221. Normally one would only use the "level" version for this command.
  1222. Setting individual items to Line and Bar can give bizarre results, but
  1223. this may be useful for something!
  1224.  
  1225.  
  1226.  
  1227.               MENU TLINE (display a menu as a total line)                  228
  1228.  
  1229. MENU TLINE level
  1230. MENU TLINE(,,)
  1231.  
  1232. Displays a section of the menu as a "total line" stretching from the
  1233. very left of the screen to the very right. The entire line will be
  1234. drawn even when the rist item is in the middle of the screen.
  1235.  
  1236.   "level" is a number ranging from 1 to 8 which specifies the part of
  1237. the menu to be affected. This is the standard form of the instruction,
  1238. and should be called during your menu definitions as otherwise it will
  1239. have no effect.
  1240.  
  1241.   You can also change the appearance of a menu after it has been vrated
  1242. using a second form of this command. For example,
  1243.  
  1244.         Menu Line(1,1) : Rem Displays menu 1,1 as a line.
  1245.  
  1246.  
  1247.  
  1248.                   MENU BAR (display a section of the
  1249.                             menu as a bar)
  1250.  
  1251. MENU BAR level
  1252. MENU BAR(,,)
  1253.  
  1254. This displays the selected menu items in the form of a vertical bar.
  1255. The width of this bar is automatically set to the dimensions of the
  1256. largest item in your menu.
  1257.  
  1258.   "level" is a number which indicates which part of the current menu
  1259. definition is to be affected. As a default this option is used for
  1260. levels 2 to 8 in your menu. Note that this form of the MENU BAR
  1261. instruction may only be used during your programs initialisation phase.
  1262.  
  1263.   (,,) is a list of parameters which allow you to change the style of
  1264. your menus once they've been installed. Here's an example of Menu Bar
  1265. and Menu Tline:
  1266.  
  1267.         FLAG=0
  1268.         SET_MAN
  1269.         Do
  1270.           If Choice and Choice(1)=2 And Choice(2)=1 Then ALTER
  1271.         Loop
  1272.         Procedure SET_MEN
  1273.           Menu$(1)=" Bar Demo " : Menu$(2)=" Select Below "
  1274.           Menu$(1,1)=" I do nothing! "
  1275.           Menu$(2,1)=" Yes, press on me! "
  1276.           Menu On
  1277.         End Proc
  1278.         Procedure ALTER
  1279.           Shared ALTER
  1280.           Menu Del
  1281.           If FLAG=0 Then Menu Bar 1 : Flag=1 Else Menu Tline 1 : Flag=0
  1282.           SET_MEN
  1283.         End Proc
  1284.  
  1285.  
  1286.  
  1287.                   MENU INACTIVE (turn off menu item)                       229
  1288.  
  1289. MENU INACTIVE level
  1290. MENU INACTIVE(,,)
  1291.  
  1292. As its name suggests, MENU INACTIVE deactivates a series of options in
  1293. your menu. Any subsequent attempts to select these items will be
  1294. completely ignored. "level" allows you to deactivate an entire section
  1295. of the menu and you can also deactivate individual menu options with
  1296. the parameters (,,). These indicate the precise position of your item
  1297. in the current menu hierarchy.
  1298.  
  1299.   Note that the menu items you've turned off with the instruction will
  1300. be immediately replaced by the INACTIVE$ string you specified during
  1301. your original menu definition. If this was omitted, any unavailable
  1302. menu options will be shown in italics.
  1303.  
  1304.  
  1305.  
  1306.                   MENU ACTIVE (activate a menu item)
  1307.  
  1308. MENU ACTIVE level
  1309. MENU ACTIVE(,,)
  1310.  
  1311. Simply reverses the effect of a previous MENU INACTIVE command. After
  1312. you've called this instruction, the selected options will automatically
  1313. redisplayed using their original title strings.
  1314.  
  1315.  
  1316. Moveable menus
  1317. ==============
  1318. AMOS menus can be displayed at any point on the screen. Menus can be
  1319. moved either explicity by your program or directly by the user.
  1320.  
  1321.  
  1322.  
  1323.             MENU MOVABLE (activate automatic menu movement)
  1324.  
  1325. MENU MOVABLE level
  1326. MENU MOVABLE(,,)
  1327.  
  1328. Informs the menuing system that the menu items at "level" may be moved
  1329. directly by the user - this is the default.
  1330.  
  1331.   The second form of this command allows you to set the status of each
  1332. individual item in the menu. The parameters between the brackets can
  1333. indicate any position in the menu hierarchy.
  1334.  
  1335.   Any menu may be repositioned by moving the mouse pointer over the
  1336. FIRST item in the menu and pressing the left mouse button. A
  1337. rectangular box will now appear around the selected menu item, and this
  1338. may be moved to nay point on the current screen. When you release the
  1339. left button the menu will be redrawn at the new position along with all
  1340. the associated menu items.
  1341.  
  1342.   Note that this command does not allow you to change the arrangement
  1343. of any items below this level. If you want to manipulate the individual
  1344. menu options you'll need to use a seaparate MENU ITEM command. See
  1345. EXAMPLE 16.12 for a demonstration of this system.
  1346.  
  1347.  
  1348.  
  1349.                   MENU STATIC (fix a menu into place)                      230
  1350.  
  1351. MENU STATIC level
  1352. MENU STATIC(,,)
  1353.  
  1354. Defines the menu at "level" to be immoveable by the user. One problem
  1355. with moveable menu is that the amount of the memory they consume will
  1356. change during the course of a program. If your menus are particularly
  1357. large, or if memory is running tight, this can cause real problems as a
  1358. single careless action by the user will abort your program with an
  1359. "out of memory" error. With the help of the MENU STATIC command you can
  1360. avoid this difficulty completely.
  1361.  
  1362.  
  1363.  
  1364.                         MENU ITEM MOVABLE (move
  1365.                        individual menu options)
  1366.  
  1367. MENU ITEM MOVABLE level
  1368. MENU ITEM MOVABLE(,,)
  1369.  
  1370. This command is similar to MENU MOVABLE except that it allows you to
  1371. re-arragne the various options in a particular level. So all the items
  1372. in a menu bar may been individually repositioned by the user.
  1373.  
  1374.   Normally it's illefal to move the items outside the current menu bar,
  1375. but this can be overridden using the MENU SEPARATE command.
  1376.  
  1377.   In order for the menu items to be moveable, the WHOLE menu bar must
  1378. also be moveable. So if you fix the MENU into palce with MENU STATIC,
  1379. this command will have no effect. Additionally you can't move the first
  1380. item in the menu bar as this will move the entire line. Another side
  1381. effect is that moving the last menu item will permanently reduce the
  1382. size of your menu bar. There are two possible solutions:
  1383.  
  1384.  * Enclose your entire bar with a rectangular box like so:
  1385.  
  1386.         Menu$(1,1)=,,,"(Bar 40,100)(Loc 0,0)"
  1387.  
  1388. Where MENU$(1,1) is the first item in your current bar.
  1389.  
  1390.  * Set the last item into place with MENU ITEM STATIC.
  1391.  
  1392.  
  1393.  
  1394.                   MENU ITEM STATIC (static menu item)
  1395.  
  1396. MENU ITEM STATIC level
  1397. MENU ITEM STATIC(,,)
  1398.  
  1399. This command locks one or more menu items firmly into place and is the
  1400. default setting.
  1401.  
  1402.  
  1403.  
  1404.              MENU SEPARATE (separate a list of menu items)                 231
  1405.  
  1406. MENU SEPARATE level
  1407. MENU SEPARATE(,,)
  1408.  
  1409. Tells AMOS to separate all the items in the current level. Each item in
  1410. your menu istreated completely independently from the previous one. If
  1411. you haven't defined a background string, each item will be offset by
  1412. two pixels from the one above. This creates an attractive stepped
  1413. effect which can be removed by editing the menu with the MENU
  1414. Accessory.
  1415.  
  1416.   The optional parameters to this instruction allow you to split a menu
  1417. bar at any point in the line. Once you've separated an item it will be
  1418. affected by the MENU MOVABLE commands rather than ITEM instructions.
  1419.  
  1420.  
  1421.  
  1422.                  MENU LINKED (link up a set of menus)
  1423.  
  1424. MENU LINKED level
  1425. MENU LINKED(,,)
  1426.  
  1427. This links one or more menu items together. It's the opposite of the
  1428. MENU SEPARATE instruction.
  1429.  
  1430.  
  1431.  
  1432.               =MENU X (return the graphical X coordinate
  1433.                            of an menu item)
  1434.  
  1435. x=MENU X(,,)
  1436.  
  1437. The MENU X function allows you to retrieve the position of a menu item
  1438. relative to the previous option on the screen. You can use this
  1439. information to implement powerful menus such as the one found in
  1440. EXAMPLE 16.13.
  1441.  
  1442.  
  1443.  
  1444.               =MENU Y (return the graphical Y coordinate
  1445.                             of a menu item)
  1446.  
  1447. x=MENU Y(,,)
  1448.  
  1449. Returns the Y coordinate of a menu option. note that all coordinates
  1450. are measured relative to the previous item. So this is NOT a standard
  1451. screen coordinate!
  1452.  
  1453.  
  1454. Moving a menu within a program
  1455. ==============================
  1456.  
  1457.  
  1458.              MENU BASE (move the starting point of a menu)
  1459.  
  1460. MENU BASE x,y
  1461.  
  1462. This command moves the starting point of the first level of your menus
  1463. to the absolute csreen coordinates x,y. All subordatine menu items will
  1464. be displayed at their curent positions relative to the top of your
  1465. menu. See EXAMPLE 16.14 for a demonstration of the MENU BASE command in
  1466. action.
  1467.  
  1468.  
  1469.  
  1470.                         SET MENU (move a menu)                             232
  1471.  
  1472. SET MENU (,,) TO x,y
  1473.  
  1474. Sets the coords of the top left corner of a menu item. These
  1475. coordinates are measured relative to the previous level. The starting
  1476. point for the entire menu (coords 0,0) may be set with the MENU BASE
  1477. command.
  1478.  
  1479.   All the lvels of the menu below your menu wlil also be moved by this
  1480. instruction. Their relative positons will be unchanged. SInce x,y can
  1481. be negative numbers, it's possible to arrange the items in a menu bar
  1482. in the form of a control panel - see EXAMPLE 16.15.
  1483.  
  1484. Displaying a menu at the cursor position
  1485.  
  1486.              MENU MOUSE (display the menu under the mouse)
  1487.  
  1488. MENU MOUSE ON/OFF
  1489.  
  1490. The MENU MOUSE features automatically display all menus starting from
  1491. the current position of the mouse cursor. The mouse coordinates are
  1492. added to the MENU BASE to get the final position, so it's possible to
  1493. place the menu a fixed distance away from the mouse pointer if
  1494. required. See EXAMPLE 16.16.
  1495.  
  1496. 17: SOUND AND MUSIC
  1497. The Amiga's sound system is capable of generating stereo sound effects
  1498. which would have been unheard of just a few years ago. The results are
  1499. impressive even through your TV speaker, but when you connect your
  1500. Amiga to a Hi-Fi, the sounds can actually shake your room!
  1501.  
  1502.   As you would expect from AMOS, we've come a long way since the humbe
  1503. BEEP command. In fact, we've provided everything you need to
  1504. incorporate mind-blowing sound effects in your own games. All the AMOS
  1505. sound commands are performed independently of your Basic programs. So
  1506. your soundtracks can be played continuously, without affecting the
  1507. quality of the game-play in the slightest.
  1508.  
  1509.   Samples may be created using any of the available sampling cartridges
  1510. and can be replayed with a simple SAMPLAY instruction. Each sample can
  1511. be output in a variety of speeds, and may be looped repeatedly. It's
  1512. even possible to play a sample as a musical note.
  1513.  
  1514.   Music can be converted over from a separate package such as SONIX,
  1515. SOUNDTRACKER or GMC. The AMOS Music system is intelligent and will
  1516. automatically stop when a sound is played through the current channel,
  1517. thus allowing you to effortlessly combine both samples and music in the
  1518. same sound channel, without the risk of unwanted interference effects.
  1519.  
  1520.   Each song can incorporate up to 256 separate instruments; the only
  1521. limit to the number of songs is the amount of available memory. In
  1522. order to keep the memory overhead down to an absolute minimum, all
  1523. tunes are built up of a number of separate patterns. Once a pattern has
  1524. been created, it can be accessed anywhere in your music using just a
  1525. couple of bytes. By defining just a few key patterns, you can therefore
  1526. create dozens of different tues without running short of memory.
  1527.  
  1528.   The best thing about the AMOS music system however, is that it's
  1529. expandable. The entire source code is supplied on the data disc for you
  1530. to examine or change. So you won't be left out in the cold by any
  1531. future developments on the Amiga's music scene.
  1532.  
  1533.  
  1534. Simple sound effects
  1535. ====================
  1536. We'll start off with a run down of the built-in sound effects included
  1537. in AMOS Basic. These are the AMOS equivalent to the Amiga Basic BEEP
  1538. command.
  1539.  
  1540.  
  1541.  
  1542.           BOOM (generate a noise sounding like an explosion)
  1543.  
  1544. BOOM
  1545.  
  1546. Kapow! You're dead! Use BOOM to add the appropriate stereo sound effect
  1547. in your games. Traditionally this type of "White Noise" as been
  1548. extremely difficult on the Amiga, but AMOS uses a clever interrupt
  1549. system to create a realistic explosion effect. Example:
  1550.  
  1551.         Boom : Print "You're DEAD!"
  1552.  
  1553.  
  1554.  
  1555.                SHOOT (create a noise like a gun firing)
  1556.  
  1557. SHOOT
  1558.  
  1559. This command generates a simple gunshot effect. Like BOOM, SHOOT does
  1560. not halt your program in any way. So if you're firing several
  1561. successive shots, you may wish to add a small delay using WAIT.
  1562.  
  1563.         Shoot : Wait 6 : Shoot : Print "You're DEAD!"
  1564.  
  1565.  
  1566.  
  1567.                        BELL (simple bell sound)                            234
  1568.  
  1569. BELL [f]
  1570.  
  1571. BELL produces a pure tone with frequency f. f sets the pitch of the
  1572. note, from 1 (very deep) to 96 (very high).
  1573.  
  1574.  
  1575. Sound channels
  1576. ==============
  1577. The Amiga's hardware can effortlessly play up to four different sounds
  1578. simultaneously. This allows you to add attractive harmonics to your
  1579. sound effects.
  1580.  
  1581.   Each sound can be output through one of four VOICES numbered from
  1582. 0 to 3. You can think of these voices as a separate instruments which
  1583. can independently play their own sequence of notes, samples or music.
  1584. All four voices are internally combined to generate the final sound you
  1585. hear through your speaker system.
  1586.  
  1587.   The AMOS sound instructions will happily play your sounds using any
  1588. arrangement of voices you like. All AMOS sound commands use a standard
  1589. way of entering your voice settings. Each voice is assigned a
  1590. particular bit in a VOICE parameter like so:
  1591.  
  1592.         Bit 0 -> Voice 0
  1593.         Bit 1 -> Voice 1
  1594.         Bit 2 -> Voice 2
  1595.         Bit 3 -> Voice 3
  1596.  
  1597. To activate the required voices, set the appropriate bits to 1. Here's
  1598. a list of common values to make things a little easier
  1599.  
  1600.         Value  Voice used  Effect
  1601.         -----  ----------  ------
  1602.          15     0,1,2,3    Uses all four voices
  1603.           9     0,3        These voices are combined together and
  1604.                            output to the left speaker.
  1605.           8     3
  1606.           6     2,4        Played through the RIGHT speaker.
  1607.           4     2
  1608.           2     1
  1609.           1     0
  1610.  
  1611. In order to do justice to the resulting sound effects, you'll almost
  1612. certainly need to connect your Amiga to a Hi-Fi system of some sort.
  1613. Most TVs are just not capable of reproducing the full range of sounds
  1614. which can be generated by the Amiga's amazing hardware.
  1615.  
  1616.  
  1617.  
  1618.                    VOLUME (change the sound colume)                        235
  1619.  
  1620. VOLUME [v,] intensity
  1621.  
  1622. VOLUME changes the volume of the sounds which are to be played through
  1623. one or more sound channels.
  1624.  
  1625.   "intensity" refers to the loudness of this sound. It can normally
  1626. range from 0 (silent) to 63 (maximum). As a default, the volume is set
  1627. to the same intensity for all four of the available voices. THe new
  1628. volume will be used for all future sound effects, including music.
  1629.  
  1630.   The v parameter lets you change the volume of each voice
  1631. independently. v now indicates which combination of voices are to be
  1632. regulated. This second option is only used by the sound effects. It has
  1633. no affect on any music you're playing. The voices are selected using a
  1634. bit amp in the standard format, with each bit representing state of a
  1635. single sound channel. If the bit is set to 1, then the volume of this
  1636. voice will be changed, otherwise it will be unaffected. Examples:
  1637.  
  1638.         Volume %0001,63 : Boom : Wait 100
  1639.         Volume %1110,10 : Boom : Wait 50
  1640.         Play 40,0 : Wait 30
  1641.         Volume 50 : Play 40,0
  1642.  
  1643.  
  1644. Sampled sound
  1645. =============
  1646. If you had to generate all the sound effects you need, directly inside
  1647. your computer, you would be faced with an impossible task. In practive,
  1648. it's often much easier to take a real sound from an external source,
  1649. such as a tape recorder, and convert it into a list of numbers which
  1650. can be held in your computer's memory.
  1651.  
  1652.   Eacn number represents the volume of a particular sample of the
  1653. sound. By rapidly playing these values back through the Amiga's sound
  1654. chips, you can recreate a realistic impression of the original sound.
  1655. This technique forms the basis of the sampled sound effects found in
  1656. most modern computer games.
  1657.  
  1658.   If you want to create your own samples, you'll be forced to buy a
  1659. separate piece of hardware known as a SAMPLER CARTRIDGE. Although these
  1660. cartridges are fun, they're certainly not essentia. AMOS Basic is
  1661. perfectly capable of playing any existing sound sample, without the
  1662. need for any expensive add-ons.
  1663.  
  1664.   Currently there are hunderds of sound effects available from the
  1665. public domain (PD), covering the vast majority of the effects you'll
  1666. need in your games. We've even included a selection of useful samples
  1667. on the AMOS data disc for you to experiment with.
  1668.  
  1669.  
  1670.  
  1671.                   SAM PLAY (play a sound sample from
  1672.                          the AMOS sample bank)
  1673.  
  1674. SAM PLAY s
  1675. SAM PLAY v,s
  1676. SAM PLAY v,s,f          The SAMP PLAY instruction plays a sampled sound
  1677.                         straight through your loudspeaker system. All
  1678. samples are normally stored in memory bank number 5, but this may be       236
  1679. freely changed using the SAM BANK command.
  1680.  
  1681.   s is the number of the sample bank which is to be played. There's no
  1682. limit of the samples you can store in a bank other than the available
  1683. memory. If you want to use your own samples with this instruction,
  1684. you'll need to incorporate them into an AMOS memory bank. Full details
  1685. can be found towards the end of this section.
  1686.  
  1687.   v is a bit-map containing a list of voices your sample will use. As
  1688. usual, there's one bit for each possible voice. To play your samples
  1689. through the required voice, simply set the relevant bit to 1.
  1690.  
  1691.   f holds the playback speed of your sample, measured in hertz. This
  1692. specifies the number of samples which are to be played each second.
  1693. Typical sample speeds range from 4000, for noises such as explosions,
  1694. to 10000 for recognisable speech effects. By changing the playback
  1695. rate, you can freely adjust the pitch of your sound over a large range.
  1696. So a single sample can be used to generate dozens of different sounds.
  1697. Example:
  1698.  
  1699.         Load "AMOS_DATA:Samples/Sample_Demo.abk"
  1700.         For S=1 To 11
  1701.           Locate 0,0 : ? "Playing sample ";S
  1702.           Sam Play S
  1703.           Locate 0,24 :Centre "<Hit a key to continue>" :Wait Key :Cline
  1704.         Next S
  1705.         Wait Key
  1706.         Sam Play 1,11 : Wait 5 : Sam Play 2,11
  1707.         Wait key
  1708.         Sam Play 1,1,2000
  1709.         Wait Key
  1710.         Sam Play 1,1,15000
  1711.  
  1712. A further demonstration of this command can be found in EXAMPLE 17.1
  1713.  
  1714.  
  1715.  
  1716.                   SAM BANK (change the current bank)
  1717.  
  1718. SAM BANK n
  1719.  
  1720. Assigns a new memory bank to be used for your samples. All future
  1721. SAM PLAY instructions will now take their sounds directly from this
  1722. bank.
  1723.  
  1724.   It's possible to exploit this feature to hold several complete sets
  1725. of samples alongide each other. You can then between these samples at
  1726. any time, with just a simple call to the SAM BANK.
  1727.  
  1728.  
  1729.  
  1730.                   SAM RAW (play a sample from memory)
  1731.  
  1732. SAM RAW voice,address,length,frequency
  1733.  
  1734. Plays a raw sample stored anywhere in the Amiga's memory. "voice" is a     237
  1735. bit-pattern in standard format which specifies the list of voices your
  1736. sample is to use. Each bit in the pattern selects a single channel to
  1737. be played (see sound channels).
  1738.  
  1739.   "address" holds the address of your sample. Normally, this will refer
  1740. to the inside of an existing AMOS memory bank. "length" contains the
  1741. length of the sample you wish to play. "frequency" indicates the sample
  1742. speed to be used for the playback (in samples per second or Hz). This
  1743. may be very different to the rate at which the sample was originally
  1744. recorded.
  1745.  
  1746.   SAM RAW lets you play standard Amiga samples straight through your
  1747. loudspeaker, without the need to create a special memory bank (see
  1748. Creating a sample bank). It's now your responsibility to manage your
  1749. samples in memory, and enter the sample parameters by hand. SAM RAW is
  1750. great for browsing through files from your disc collection. Use BLOAD
  1751. to hold a file in a bank and then use SAM RAW to play the data. With
  1752. luck you should come across some interesting sounds. Examples:
  1753.  
  1754.         Reserve As Work 10,55000
  1755.         Bload "Samples/Samples.abk",start(10)
  1756.         Sam Raw 15,start(10,length(10),10000
  1757.  
  1758.  
  1759.  
  1760.                       SAM LOOP (repeat a sample)
  1761.  
  1762. SAMP LOOP ON/OFF
  1763.  
  1764. The SAM LOOP directive informs AMOS Basic that all subsequent samples
  1765. are to be repeated continuously. Examples:
  1766.  
  1767.         Load "AMOS_DATA:Samples/Sampledemo.abk"
  1768.         Sam Loop On
  1769.         For S=1 To 11
  1770.           Locate 0,0 : Print "Playing sample ";S
  1771.           Sam Play S
  1772.           Locate 0,24 : Centre "<Hit a key to continue>":Wait Key :Cline
  1773.         Next S
  1774.         Sam Loop Off
  1775.  
  1776. This looping effect can be deactivated with a simple call to the
  1777. SAM LOOP OFF command.
  1778.  
  1779.  
  1780. Creating a sample bank
  1781. ======================
  1782. If you're indenting to play your own samples using SAM PLAY, you'll
  1783. first need to load them into a memory bank. This can be achieved with
  1784. the SAMMAKER program supplied on the AMOS data disc.
  1785.  
  1786.   On start-up, SAMMAKER presents you with a standard AMOS file
  1787. selector. Enter the filename of the first sample to be stored in your
  1788. new bank, and press RETURN. If AMOS can't find the sampling rate,
  1789. you'll be asked to enter it directly. It doesn't really matter if you
  1790. make a mistake at this point, as you can safely replay your samples at
  1791. any speed you like.
  1792.  
  1793.   After a short delay, you'll be prompted for the next sample to be
  1794. installed into the bank. When you've reached the end of your samples,
  1795. type SAVE at the file selector to save your samples onto the disc.
  1796. You'll be automatically prompted for the destination filename of your
  1797. new bank. This can now be entered into AMOS Basic using the LOAD
  1798. command like so:
  1799.  
  1800.         Load "Sample.abk"
  1801.         Load "Sample.abk",6 : Rem Loads sample into bank #6.               238
  1802.  
  1803.  
  1804.  
  1805. Music
  1806. =====
  1807. The AMOS music system allows you to easily add an attractive backing
  1808. track to your games. Music can be created from a variety of sources,
  1809. including GMC, SOUNTRACKER or SONIX.
  1810.  
  1811.   In order to convert these musics into the special AMOS format, you'll
  1812. need to use one of the translation programs included on the AMOS data
  1813. disc. GMC music should have been saved using the SAVE DATA icon, as
  1814. this copies both the music and the instrument definitions into a single
  1815. large data file.
  1816.  
  1817.  
  1818.  
  1819.                      MUSIC (play a piece of music)
  1820.  
  1821. MUSIC n
  1822.  
  1823. The AMOS MUSIC command starts a piece of music from the music bank
  1824. (#3). This music will be played independently of your Basic program,
  1825. without affecting it in the slightest.
  1826.  
  1827.   Normally, it's possible to store several complete arrangements in the
  1828. same bank. Each composition is assigned its own individual music
  1829. number. The only exception to this rule is music created by GMC, which
  1830. only allows you to place one song in the bank at a time. Example:
  1831.  
  1832.         Load "MUSIC/Musicdemo.abk"
  1833.         Music 1
  1834.  
  1835. The AMOS music system is intelligent, and will automatically suspend
  1836. your music for the duration of any subsequent sound effects on the
  1837. current channel. When the sound has finished, your tune will be
  1838. restarted from its previous position. Up to three separate tunes can be
  1839. started at a time. Each new music command stops the current song, and
  1840. pushes its status onto a stack. Once the song has concluded, the old
  1841. music will commence from where it left off.
  1842.  
  1843.  
  1844.  
  1845.               MUSIC STOP (stop a single section of music)
  1846.  
  1847. MUSIC STOP
  1848.  
  1849. Halts the current piece of music. If another music is active, it will
  1850. be restarted immediately.
  1851.  
  1852.  
  1853.  
  1854.                     MUSIC OFF (turn off all music)
  1855.  
  1856. MUSIC OFF
  1857.  
  1858. THe MUSIC OFF command deactivates your music completely. In order to
  1859. restart it, you'll need to execute your original series of MUSIC
  1860. instructions again from scratch.
  1861.  
  1862.  
  1863.  
  1864.              TEMPO (change the speed of a sample of music)                 239
  1865.  
  1866. TEMPO s
  1867.  
  1868. TEMP modifies the speed of any tune which is currently being played
  1869. with the MUSIC command. s is the new speed, and can range from 1 (very
  1870. slow) to 100 (very fast). Not all instruments are capable of playing at
  1871. this maximum speed, however. The practical limit is closer to 50. For a
  1872. demonstration, place the AMOS data disc into the current drive and
  1873. type:
  1874.  
  1875.         Load "AMOS_DATA:Music/Musicdemo.abk"
  1876.         Music 1
  1877.         Tempo 35
  1878.         Tempo 5
  1879.  
  1880. Note that music created with GMC often contains labels which set the
  1881. tempo directly inside the arrangement. These labels will override the
  1882. tempo settings within AMOS Basic. So it's not advisable to use them in
  1883. your own music.
  1884.  
  1885.  
  1886.  
  1887.              MVOLUME (set the volume of a piece of music)
  1888.  
  1889. MVOLUME n
  1890.  
  1891. Changes the volume of the entire piece of music to intensity n (0-63).
  1892.  
  1893.  
  1894.  
  1895.                   VOICE (activate one or more voices
  1896.                          of a piece of music)
  1897. VOICE mask
  1898.  
  1899. Activates one or more voices of the music independently. Usually each
  1900. voice will contain its own separate melody which will combined through
  1901. your speakers to generate the eventual music.
  1902.  
  1903.   "mask" is a bit mask in the normal AMOS format which specifies which
  1904. voices you wish to play. Each bit represents the state of one voice in
  1905. the music. If it's set to 1, the voice will be played, otherwise it
  1906. will be totally unused.
  1907.  
  1908.         Load "AMOS_DATA:Music/Musicdemo.abk"
  1909.         Music 1
  1910.         For V=0 To 15
  1911.         Locate 0,0 : Print "Voice ";V
  1912.         Voice V
  1913.         Wait 100
  1914.         Next V
  1915.         Direct
  1916.         Voice %0001 : Rem Activate voice 0                                 240
  1917.         Voice %0010 : Rem                1
  1918.         Voice %1001 : Rem                3 and 0
  1919.         Voice %1111 : Rem                4
  1920.  
  1921.  
  1922.  
  1923.                         =VUMETER (volume meter)
  1924.  
  1925. s=VUMETER(v)
  1926.  
  1927. The VUMETER function tests voice v and returns the volume of the
  1928. current note which is being played by your music. s is an intensity
  1929. value between 0 and 63. v is the number of a single voice to be checked
  1930. (0-3).
  1931.  
  1932.   Using this function, you can make your sprites dance to a piece of
  1933. music! Load EXAMPLE 17.2 for a demonstration.
  1934.  
  1935.   Note there's also an AMAL version of this intruction which allows you
  1936. to create realtime VU meters using interrupts. See the section on the
  1937. VU command for more information.
  1938.  
  1939.  
  1940. Playing a note
  1941. ==============
  1942.  
  1943.  
  1944.                           PLAY (play a note)
  1945.  
  1946. PLAY [voice,] pitch,delay
  1947.  
  1948. Plays a single note through the loudspeaker of your TV or Hi-Fi.
  1949. "pitch" sets the tone of this sound, ranging from 0 (low) to 96 (high).
  1950. Rather than just being an arbitrary number, each pitch is associated
  1951. with one of the notes (A,B,C,D,E,F,G). This can be seen from the
  1952. following table.
  1953.  
  1954.                            Octave
  1955.               --------------------------------
  1956.                0   1   2   3   4   5   6   7
  1957.         Note                Pitch
  1958.         ----  --------------------------------
  1959.         C     1   13  25  37  49  61  73  85
  1960.         C#    2   14  26  38  50  62  74  86
  1961.         D     3   15  27  39  51  63  75  87
  1962.         D#    4   16  28  40  52  64  76  88
  1963.         E     5   17  29  41  53  65  77  89
  1964.         F     6   18  30  42  54  66  78  90
  1965.         F#    7   19  31  43  55  67  79  91
  1966.         G     8   20  32  44  56  68  80  92
  1967.         G#    9   21  33  45  57  69  81  93
  1968.         A     10  22  34  46  58  70  82  94
  1969.         A#    11  23  35  47  59  71  83  95
  1970.         B     12  24  36  48  60  72  84  96
  1971.  
  1972. It should be apparent that the notes go up in a cycle of 12. This cycle    241
  1973. is known as an octave.
  1974.  
  1975.   The optional voice parameter allows you to play your notes through
  1976. any combination of the Amiga's four voices. As usutal it's a bit-map in
  1977. the format:
  1978.  
  1979.         Bit  Voice
  1980.         ---  -----
  1981.          0     0              Setting a bit to a value of 1 plays the
  1982.          1     1              relevant voice. "delay" sets the length
  1983.          2     2              of the pause between the play command and
  1984.          3     3              the next Basic instruction. This allows
  1985.                               you to play each note before preceding
  1986.                               the next one.
  1987.  
  1988. A delay of zero starts a note and immediately jumps to the next Basic
  1989. instruction. By playing several notes after another, you can easily
  1990. generate some attractive harmonic effects. Examples:
  1991.  
  1992.         Play 1,40,0 : Play 2,50,0
  1993.         Wait Key
  1994.         Play 1,40,15 : Play 2,50,15
  1995.         Do
  1996.           T=Rnd(96) : V=Rnd(15) : Play V,T,3
  1997.         Loop
  1998.  
  1999. PLAY is not limited to pure notes incidentally. It's also possible to
  2000. assign complex waveforms to the sound generator using the powerful WAVE
  2001. and NOISE commands.
  2002.  
  2003.  
  2004. Waveforms and envelopes
  2005. =======================
  2006.  
  2007.  
  2008.                      SET WAVE (define a waveform)
  2009.  
  2010. SET WAVE wave,shape$
  2011.  
  2012. The SET WAVE instruction provides you with the ability to define your
  2013. very own instruments for use with the AMOS Basic PLAY instruction. The
  2014. sound of yur instrument depends on the shape of a waveform held in the
  2015. Amiga's memory. This forms a template which is repeated to produce your
  2016. final note.
  2017.  
  2018.   "wave" is the number of the waveform you wish to define. Allowable
  2019. wave numbers start from 2 onwards. That's because waves zero and 1 are
  2020. already installed. Wave zero holds a random noise pattern for producing
  2021. explosion effects. Wave one is a smooth sine wave and generates the
  2022. pure tones used by the standard PLAY instruction.
  2023.  
  2024.   The shapes of your waveform are set using a list of 256 numbers which
  2025. are entered using the SHAPE$ parameter. Now look at the uppest diagram
  2026. in the AMOS4.PIC (file included with this manual packet).
  2027.  
  2028.          < picture AMOS4.PIC, the uppest diagram >                         242
  2029.  
  2030.   Each number represents the intensity of an individual section of the
  2031. waveform. This is equivalent to the height of just one point in the
  2032. diagram. Possible values for intensity range from -128 to 127. Since
  2033. AMOS strings are only capable of holding *positive* numbers (0-255),
  2034. you'll need to convert your negative values into a special internal
  2035. format before use. The required value can be calculated by simply
  2036. adding 256 to the negative numbers in your list.
  2037.  
  2038.   Here's a program which demonstrates how the triangular wave in the
  2039. previous diagram could be created in AMOS Basic
  2040.  
  2041.         S$=""
  2042.         For I=-128 To 127
  2043.           X=I : If X<0 Then Add X,256
  2044.           S$=S$+Chr$(X)
  2045.         Next I
  2046.         Set Wave 2,S$
  2047.  
  2048. Before playing your waveform you have to tell AMOS Basic which channels
  2049. are to be assigned to your wave. This can be achieved using the WAVE
  2050. command. Add the following line to the previous routine
  2051.  
  2052.         Wave 2 To 15 : For S=10 To 60 : Play S,10 : Next S
  2053.  
  2054. The Best way to reproduce the effect of a real instrument is to combine
  2055. several SINE waves together. An example of one of these sine waves can
  2056. be seen in the picture AMOS4.PIC:
  2057.  
  2058.          < picture AMOS4.PIC, the diagram in the middle >                  243
  2059.  
  2060. Adding several of these waves together, with different sizes and
  2061. separate starting points, produces waves in the following pattern:
  2062.  
  2063.          < picture AMOS4.PIC, the lowest diagram >
  2064.  
  2065. This generates the smooth harmonics needed for your notes. Here's an
  2066. example:
  2067.  
  2068.         SHAPE$="" : Degree
  2069.         For S=0 To 255
  2070.           V=Int((Sin(S)/2+SIN(S*2+45)/4)*128)+127
  2071.           SHAPE$=SHAPE$+Chr$(V)
  2072.         Next S
  2073.         Set Wave 2,SHAPE$ : Wave 2 to 15
  2074.         For N=10 to 60 : Play N,10 : Next N
  2075.  
  2076.  
  2077.  
  2078.           WAVE (assign a wave to one or more sound channels)
  2079.  
  2080. WAVE w To v
  2081.  
  2082. WAVE assigns wave number w to one or more sound channels. v contains a
  2083. bit-map in the standard format. If a bit in the pattern is set to 1
  2084. then the approrpriate voices are used by PLAY, otherwise they will be      244
  2085. completely unaffected.
  2086.  
  2087.   As a default, wave zero is reserved for the NOISE channel, and wave
  2088. one contains a sine wave. Here are some examples:
  2089.  
  2090.         Wave 0 To %0001
  2091.         Play 1,40,0
  2092.         Wave 0 To %1100
  2093.         Play 20,10
  2094.         Wave 1 To %1111
  2095.         Play 60,0
  2096.  
  2097.  
  2098.                NOISE (assign a noise wave to a channel)
  2099.  
  2100. NOISE TO voices
  2101.  
  2102. Applies a white noise effect (wave 0) to the selected voices. Load
  2103. EXAMPLE 17.3 for a demonstration.
  2104.  
  2105.   "voices" is a standard bit pattern. The first four bits represent the
  2106. four possible voices, starting from zero. NOISE is equivalent to the
  2107. command:
  2108.  
  2109.         Wave 0 To voices
  2110.  
  2111. Examples:
  2112.  
  2113.         Noise To 15
  2114.         Play 60,0
  2115.         Play 30,0
  2116.  
  2117.  
  2118.  
  2119.                        DEL WAVE (delete a wave)
  2120.  
  2121. DEL WAVE n
  2122.  
  2123. Deletes a wave which has previously been defined using SET WAVE. n is
  2124. the number of the wave, and starts at 2. It's impossible to delete the
  2125. built-in NOISE ans SINE waves using this instruction. After the wave
  2126. has been erased, all voices will be reset to the standard SINE wave
  2127. (default).
  2128.  
  2129.  
  2130.  
  2131.                   SAMPLE (assign a sample to a wave)
  2132.  
  2133. SAMPLE n TO voices
  2134.  
  2135. This is the most powerful cersion of all the wave commands. It assigns
  2136. a sample stored in the sample bank to the current wave. Play will now
  2137. take an instrument straight from the sample bank.
  2138.  
  2139.         Load "Samples/sample1.abk"                                         245
  2140.         Sample 1 To 15
  2141.         For I=20 To 50
  2142.           Play I,50
  2143.         Next I
  2144.  
  2145. As usual "voices" allows you to select a range of voices to be set by
  2146. the instruction. It's a standard bit-map; Bit 0 -> Voice 0   etc...
  2147.  
  2148.   Note!: The range of notes that a sample can be played with, depends
  2149. on its original recording rate. If a note is too high, AMOS may not be
  2150. able to play it at all. The acceptable range varies from a sample to
  2151. sample, but it's usually between 10 and 50.
  2152.  
  2153.  
  2154.  
  2155.                  SET ENVEL (create a volume envelope)
  2156.  
  2157. SET ENVEL wave,phase TO duration,volume
  2158.  
  2159. The SET ENVEL command smoothly changes the volume of a note while it's
  2160. being played. In the real world, sounds don't just sprint into
  2161. existence fully formed. They tend to evolve over a period of time,
  2162. according to a pattern known as the volume envelope. The shape of this
  2163. envelope varies depending on the type of instrument you are playing. A
  2164. typical example of one of these envelopes is shown in the picture
  2165. AMOS5.PIC.
  2166.  
  2167.          < picture AMOS5.PIC >
  2168.  
  2169. The sound is split up into four phases: Attack decay, sustain and
  2170. release. AMOS Basic allows you to define your envelopes using up to        246
  2171. seven separate steps. Each step represents a steady change in the
  2172. volume of the current note.
  2173.  
  2174.   "wave" is a number of the waveform which will be affected by this
  2175. instruction. It's possible to use any waveform you like for this
  2176. purpose, including the built-in NOISE and SINE generators.
  2177.  
  2178.   "phase" holds the number of the particular phase which is to be
  2179. defined, ranging from 0 to 6.
  2180.  
  2181.   "duration" specifies the length of the current step in units of a
  2182. 50th of a second. This determines the apparent speed of the volume
  2183. change to be generated in this phase.
  2184.  
  2185.   "volume" specifies the volume which is to be reached by the end of
  2186. this phase. Allowable volume levels range from 0-63.
  2187.  
  2188.   It's important to understand that this volume is relative to the
  2189. intensity you've previously st with the VOLUME command. So even if the
  2190. note is quiet, the shape of the envelope will be perfectly reserved.
  2191. Now for some examples:
  2192.  
  2193.         Set Envel 1,0 To 200,63 : Rem Sets the 1st step.
  2194.         Play 40,0
  2195.  
  2196. As you can hear, the volume of your sound starts from zero, and
  2197. increases to a maximum intensity during the length of the note. Now
  2198. let's try defining something a little more complicated.
  2199.  
  2200.         Set Envel 1,0 To 15,60
  2201.         Play 40,0 : Wait Key
  2202.         Set Envel 1,1 To 1,50
  2203.         Play 40,0 : Wait Key
  2204.         Set Envel 1,2 To 10,50
  2205.         Play 40,0 : Wait Key
  2206.         Set Envel 1,3 To 50,0
  2207.         Play 40,0
  2208.  
  2209. Finally, here's an example of a NOISE envelope:
  2210.  
  2211.         Noise To 15
  2212.         Set envel 0,0 To 1000,30
  2213.         Play 40,0
  2214.         Wait Key
  2215.         Music Off
  2216.  
  2217. Don't confuse waves and envelopes. A wave sets the frequency components
  2218. of your notes, whereas an envelope simply changes their volume
  2219. according to a set pattern.
  2220.  
  2221.  
  2222. Speech
  2223. ======
  2224. Your Amiga is supplied with a powerful speech synthesizer program which
  2225. can be found on the standard Workbench disc. With the help of this
  2226. routine, your AMOS programs can be made to speak. Speech is especially
  2227. userful in education, as many yound people will respond far better to
  2228. the spoken word than to boring text.
  2229.  
  2230.   One word of caution though. Since the narrator package is independent
  2231. of AMOS Basic, we can't attest to its absolute reliability. You're
  2232. unlikely to encounter any serious problems, but it's well worth
  2233. treating it with a littlle care.
  2234.  
  2235.  
  2236.  
  2237.                          SAY (speak a phrase)                              247
  2238.  
  2239. SAY t$[,mode]
  2240.  
  2241. The SAY command is incredibly easy to use. Enter your text in normal
  2242. English, concluding your phrase with a punctuation mark such as full
  2243. stop. SAY will now translate your words into an internal format and
  2244. speak them directly through your loudspeaker. Example:
  2245.  
  2246.         Say "AMOS Basic can really speak"
  2247.  
  2248. The first time you use this instruction, the narrator.device will
  2249. automatically be loaded from disc. So it's vital to ensure that an
  2250. appropriate disc is placed in the current drive before using this
  2251. system, as otherwise you may get an Intuition style requester box.
  2252.  
  2253.   "mode" toggeles between two separate speech modes. As a default, your
  2254. program will wait for the duration of the speech, and any music or
  2255. sound effects will be temporarily suspended. Setting "mode" to a value
  2256. of one activates multitasking system which allows you to output your
  2257. speech whilst AMOS is executing your program. Inevitably, this will
  2258. slow down your basic routines Considerably. To return your speech back
  2259. to normal, set mode to zero.
  2260.  
  2261.   If the narrator system cannot understand what you are attempting to
  2262. speak you won't get an error messagel, but the command will be
  2263. automatically aborted. Also note that the narrator can occasionally get
  2264. slightly confused with very short sentences. Sometimes the remainder of
  2265. the previous phrase is tagged to the end of the current voice. The
  2266. problem can be solved by simply adding a list of spaces to the end of
  2267. your text. These will wipe out the unwanted speech data.
  2268.  
  2269.  
  2270.  
  2271.                      SET TALK (set speech effects)
  2272.  
  2273. SET TALK sex,mode,pitch,rate
  2274.  
  2275. This allows you to change the type of voice which will be used by the
  2276. SAY command. "sex" chooses between a male (0) or female (1). In all
  2277. honesty, it's not a particularly realistic rendition. Better effects
  2278. can be created by simply increasing the frequency of the voice using
  2279. the pitch parameter.
  2280.  
  2281.   "mode" adds a strange rhythmic pattern to the voice. This can be
  2282. activated by setting "mode" to a value of 1.
  2283.  
  2284.   "pitch" changes the frequency of the voice, from 65 to 320.
  2285.  
  2286.   "rate" specifies the speed, measured in the words per minute (40-400).   248
  2287.  
  2288.   Any of the above parameters can be omitted if required. Providing you
  2289. keep the commas in their normal positions, you can change any set of
  2290. options independently.
  2291.  
  2292.  
  2293.  
  2294. Filter effects
  2295. ==============
  2296.  
  2297.  
  2298.                    LED (activate a high pass filter/
  2299.                            change power led)
  2300.  
  2301. LED ON/OFF
  2302.  
  2303. The LED command has two completely separate actions. Not only does it
  2304. toggle the POWER led on your Amiga's console (in KickStart versions
  2305. 1.3 just makes the led a little darker), but it also controls a special
  2306. high pass filter.
  2307.  
  2308.   The filter changes the way high frequency sounds are treated by the
  2309. system. Normally, these sounds are filtered out so as to avoid the risk
  2310. of unwanted distorion effects. Unfortunately, this robs many percussion
  2311. instruments of their timbre. By turning off the filter, you can
  2312. recapture the essential quality of many instruments.
  2313.  
  2314.  
  2315.  
  2316.  
  2317.  
  2318.  
  2319.  
  2320.  
  2321.                            18: THE KEYBOARD                                249
  2322.                       --------------------------
  2323.  
  2324. AMOS Basic provides you with dozens of useful keyboard commands. These
  2325. can be used in anything from an Arcade game to an Adventure. It's even
  2326. possible to write a fully fledged wordprocessor entirely in AMOS Basic!
  2327.  
  2328.  
  2329.  
  2330.                  =INKEY$ (function to get a keypress)
  2331.  
  2332. k$=INKEY$
  2333.  
  2334. This function checks whether the user has pressed a key, and returns
  2335. its value in the string k$
  2336.  
  2337.   Note the INKEY$ command doesn't wait your input in any way. If the
  2338. user hasn't entered a character, INKEY$ will simply return an empty
  2339. string "".
  2340.  
  2341.   INKEY$ is only capable of reading keys which return a specific Ascii
  2342. character from the keyboard. Ascii is a standard code used to represent
  2343. all the characters which can be printed on the screen.
  2344.  
  2345.   It's important to realise that some keys, like HELP button or the
  2346. function keys, use a rather different format. If INKEY$ detects such a
  2347. key, it will return a character with a value of zero (CHR$(0)). You can
  2348. now find the internal scan code of this key using a separate SCAN CODE
  2349. function.
  2350.  
  2351.  
  2352.  
  2353.                =SCANCODE (input the scancode of the last
  2354.                         key input with INKEY$)
  2355.  
  2356. s=SCANCODE
  2357.  
  2358. SCANCODE returns the internal scancode of a key which has previously
  2359. entered using the INKEY$ function. This allows you to check for keys
  2360. which do not produce a character from the keyboard, such as HELP or
  2361. TAB. Type the following small example:
  2362.  
  2363.       Do
  2364.         While K$=""
  2365.           K$=Inkey$
  2366.         Wend
  2367.         If Asc(K$)=0 Then Print "You pressed a key with no ASCII Code"
  2368.         Print "The Scancode Is";Scancode
  2369.         K$=""
  2370.       Loop
  2371.  
  2372.  
  2373.                 =KEY STATE (test whether an individual                     250
  2374.                          key has been pressed)
  2375.  
  2376. t=KEY STATE(s)
  2377.  
  2378. Check if a specific button has been pressed on the Amiga's keyboard. s
  2379. is the internal scancode of the key you want to check. If this key is
  2380. currently being depressed then KEY state will return a value of true
  2381. (-1), otherwise the result will be false (0).
  2382.  
  2383.  
  2384.  
  2385.                    =KEY SHIFT (return the status of
  2386.                             the shift keys)
  2387.  
  2388. keys=KEY SHIFT
  2389.  
  2390. KEY SHIFT returns the current status of the various control keys. These
  2391. keys such as SHIFT or Alt cannot be detected using the standard INKY$
  2392. or SCANCODE system. But you can easily test for any combination of
  2393. control keys with just a single call to the KEY SHIFT function. "keys"
  2394. is a bit map in the following format:
  2395.  
  2396.         Bit  Key Tested         Notes
  2397.         ---  ----------         -----
  2398.          0   Left SHIFT
  2399.          1   Right SHIFT
  2400.          2   Caps Lock          Either ON or OFF
  2401.          3   CTRL
  2402.          4   Left ALT
  2403.          5   Right ALT
  2404.          6   Left AMIGA         C= key on some keyboards
  2405.          7   Right AMIGA
  2406.  
  2407. If a bit is set to a one, then the associated button has been held down
  2408. by the user.
  2409.  
  2410.  
  2411.  
  2412.                     INPUT$(n) (function to input n
  2413.                        characters into a string)
  2414.  
  2415. INPUT$ enters n characters straight from the keyboard, waiting for each
  2416. one in turn. As with INKEY$, these characters are not echoed onto the
  2417. screen.
  2418.  
  2419.   x$ is a string variable which will be loaded with your new
  2420. characters. n holds the number of characters to be entered. Example:
  2421.  
  2422.         Clear Key : Print "Type In Then Characters"
  2423.         C$=INPUT$(10) : Print "You entered ";C$
  2424.  
  2425. This insturction *not* the same as the standard INPUT command. The two
  2426. instuctions are completely different. Also note that there's a special
  2427. version of INPUT$ which can be used to read your characters from the
  2428. disc.
  2429.  
  2430.  
  2431.  
  2432.                      WAIT KEY(wait for a keypress)                         251
  2433.  
  2434. WAIT KEY
  2435.  
  2436. Waits for a single keypress.
  2437.  
  2438.  
  2439.  
  2440.                   KEY SPEED (change key repeat speed)
  2441.  
  2442. KEY SPEED lag,speed
  2443.  
  2444. KEY SPEED lets you tailor the speed of the keyboard to your own
  2445. particular taste. The new speed will be used for every part of the AMOS
  2446. system, including the editor.
  2447.  
  2448.   "lag" is the time in 50th of a second between pressing a key, and the
  2449. start of the repeat sequence.
  2450.  
  2451.   "speed" is the delay of second between each successive character.
  2452.  
  2453.  
  2454.  
  2455.                 CLEAR KEY (initialise keyboard buffer)
  2456.  
  2457. CLEAR KEY
  2458.  
  2459. Whwnever you enter a character from the keyboard, its Ascii code is
  2460. placed in an area of memory known as the keyboard buffer. It is this
  2461. buffer that is sampled by the INKEY$ function to get your key presses.
  2462.  
  2463.   CLEAR key erases this buffer completely, and returns your keyboard to
  2464. this original state. It's especially helpful at the start of a program,
  2465. as the buffer may well be full of unwanted information. You can also
  2466. call it immediately before a WAIT KEY comand to ensure that the program
  2467. waits for a fresh keypress before preceding.
  2468.  
  2469.  
  2470.  
  2471.             PUT KEY (Put a string into the keyboard buffer)                252
  2472.  
  2473. PUT KEY a$
  2474.  
  2475. Loads a string a characters directly into the keyboard buffer. Carriage
  2476. returns can be included using a CHR$(13) character.
  2477.  
  2478.   The most common use of PUT KEY is to set up defaults for your input
  2479. routines. Here's a demonstration:
  2480.  
  2481.         Do
  2482.           Put Key "No"
  2483.           Input "Another Game";A$
  2484.           If A$="No" Then Exit
  2485.         Loop
  2486.  
  2487.  
  2488.  
  2489. Input/Output
  2490. ============
  2491.  
  2492.                  INPUT (load a value from the user and
  2493.                           put it a variable)
  2494.  
  2495. INPUT
  2496.  
  2497. Provides you with a standard way of entering information into one or
  2498. more variables. There are two possible formats for this instrucion:
  2499.  
  2500. INPUT vars[;]
  2501.  
  2502. Enters a list of variables directly from the keyboard. "var" can
  2503. contain any set of variables you like, separated by commas. A question
  2504. mark will be automatically displayed at the current cursor position.
  2505.  
  2506. INPUT "Prompt";variable list[;]
  2507.  
  2508. Prints out the "prompt" string before entering your information. Note
  2509. that you must always place a semi-colon between your text and the
  2510. variable list. You are *not* allowed to use a comma for this purpose.
  2511.  
  2512.   The optional semi-colon ";" at the end of your variable list
  2513. specifies that the text cursor will not be affected by the INPUT
  2514. instruction, and will retain its original position after the data has
  2515. been entered.
  2516.  
  2517.   When you execute one of these commands, Basic will wait for you enter
  2518. the required information from the keyboard. Each variable in your list
  2519. must be matched by a single value from the user. These values must be
  2520. of the same as your original values, and should be separated by commas.
  2521.  
  2522.  
  2523.  
  2524.                       LINE INPUT (input a list of                          253
  2525.                    variables separated by a Return)
  2526.  
  2527. LINE INPUT "Prompt";variable list[;]
  2528.  
  2529. Line input is exactly same as INPUT, except that it uses a Return
  2530. instead of a comma to separate each value you enter from the keyboard.
  2531.  
  2532.  
  2533.  
  2534.  
  2535.  
  2536.  
  2537.                           19: OTHER COMMANDS                               254
  2538.                      ----------------------------
  2539.  
  2540.  
  2541.                                PRINT / ?
  2542.                (print a list of variables to the screen)
  2543.  
  2544. PRINT items
  2545.  
  2546. The PRINT instruction displays some information on the screen, starting
  2547. from the current cursor position.
  2548.  
  2549.   Each element in your list must be separated by either semi-colon or a
  2550. comma. A semi-colon prints the data immediately after the previous
  2551. value, whereas a comma first moves the cursor to the next TAB position
  2552. on the screen.
  2553.  
  2554.   Normally the cursor will be advanced downwards by a single line after
  2555. each PRINT instruction. This can be suppressed by adding a separator
  2556. after the print.
  2557.  
  2558.         PRINT 10,20*10,"Hel";
  2559.         PRINT "lo"
  2560.  
  2561.  
  2562.  
  2563.                        USING (formatted output)
  2564.  
  2565. PRINT USING format$;variable list
  2566.  
  2567. The USING statement is used in conjunction with PRINT to provied fine
  2568. control over the format of your printed output.
  2569.  
  2570.   format$ specifies a list of characters which defines the way your
  2571. variables will be displayed on the screen. Any normal text in this
  2572. string will be printed directly, but if you include one of the
  2573. characters ~#+-.;^ then one of a range of useful formatting operations
  2574. will be performed.
  2575.  
  2576.  ~  Formats a sting variable. Every ~ is replaced by a single character
  2577.     from your output string, taken from left to right.
  2578.  
  2579.         PRINT USING "This is a ~~~~~ demonstration of USING";"Small"
  2580.  
  2581.  #  Each hash character specifies a single digit to be printed out from
  2582.     your cariable. Any unused digits in this list will be automatically    255
  2583.     replaced by spaces.
  2584.  
  2585.  +  Adds a plus sign to a number if its positive, and a minus minus
  2586.     sign if it's negative.
  2587.  
  2588.         PRINT USING "+##";10 : PRINT USING "+##";-10
  2589.  
  2590.  -  Only includes a sign if the number is negative. Positive numbers
  2591.     are preceded by a space.
  2592.  
  2593.  .  Places a decimal point in the number, and centres it neatly on the
  2594.     screen.
  2595.  
  2596.  ;  Centres a number but doesn't output a decimal point.
  2597.  
  2598.  ^  Prints out a number in exponential form.
  2599.  
  2600.         PRINT USING "Here is a number ^";12345.678
  2601.  
  2602.  
  2603.  
  2604.                            REM / ' (comment)
  2605.  
  2606. REM comment
  2607.  
  2608. The REM statements is used to add comments to your Basic program. Any
  2609. text typed in after a REM statement will be completely ignored by AMOS
  2610. Basic.
  2611.  
  2612.         REM This is a comment
  2613.         ' this is a comment.
  2614.  
  2615. So, a quote mark "'" can also be used, but it *must* be placed at the
  2616. absolute beginning of the line.
  2617.  
  2618.  
  2619.  
  2620.                    DATA (place a list of data items                        256
  2621.                        in a AMOS Basic program)
  2622.  
  2623. The DATA statement allows you to incorporate whole lists of useful
  2624. information directly inside a Basic program. This data can be
  2625. subsequently loaded into one or more variables using the READ
  2626. instruction. Each variable in your list is separated by a single comma.
  2627.  
  2628.         DATA 1,2,3,"Hello"
  2629.  
  2630. Unlike most other Basics, the AMOS version of this instruction also
  2631. lets you include expression s as part of your data. So the following
  2632. lines of code are equally acceptable:
  2633.  
  2634.         DATA $FF50,$890
  2635.         DATA %111111111111,%1101010101
  2636.         DATA A
  2637.         Label: Data A+3/2.0-Sin(B)
  2638.         Data "Hello"+"There"
  2639.  
  2640. It's important to realise that the "A" at LABEL will be input as the
  2641. contents of variable A, and not the character A. The expression will be
  2642. evaluated automatically during the READ operation using the lastest
  2643. values of A and B.
  2644.  
  2645.   Also note that each DATA instruction must be the only statement on
  2646. the current line. Anything after this command will be totally ignored!
  2647. Data statements can be placed anywhere in your Basic program. However,
  2648. any data you store inside an AMOS procedure will not be accessible from
  2649. the main program.
  2650.  
  2651.  
  2652.  
  2653.                       READ (read some data a DATA
  2654.                       statement into a variable)
  2655.  
  2656. READ list of variables
  2657.  
  2658. Loads some informatoin stored in a DATA statement into a list of
  2659. variables. READ uses a special marker to determine the location of the
  2660. next piece of data to be entered. At the start of your program, the
  2661. marker is moved to the first item of the first DATA statement. Once
  2662. this item has been read, the marker is advanced so that it points to
  2663. the next item in your list. As you might expect, the variables you read
  2664. must be exactly the same type as the data held at the current position.
  2665. Example:
  2666.  
  2667.         T=10
  2668.         Read A$,B,C,D$
  2669.         Print A$,B,C,D$
  2670.         Data "String",2,T*20+rnd(100),"AMOS "+"Basic"
  2671.  
  2672.  
  2673.  
  2674.                 RESTORE (set the current READ pointer)                     257
  2675.  
  2676. RESTORE Label
  2677. RESTORE LABEL$
  2678. RESTORE Line           RESTORE changes the point at which a subsequent
  2679. RESTORE number         READ operation will expect to find the next DATA
  2680.                        statement. Each AMOS procedure has its own
  2681. individual data pointer. So any calls to this command wlil only apply
  2682. to the *current* procedure!
  2683.  
  2684.   "label" is a label which specifies the position of the first DATA
  2685. statement to be read. This label name can be calculated as part of an
  2686. expression. The following Basic commands are perfectly legal:
  2687.  
  2688.         RESTORE L
  2689.         RESTORE "L"+"A"+"B"+"E"+"L"
  2690.  
  2691. Similarly, line selects the line number of the next DATA statement.
  2692. Like "label" it can be entered as an expression:
  2693.  
  2694.         RESTORE TEST+2
  2695.  
  2696. By allowing you to jump at will through the DATA statements in your
  2697. program, RESTORE lets you choose your information depending on the
  2698. actions of the user. Each room of an adventure, for instance, could
  2699. have its description stored in a list of simple DATA statements. To
  2700. read this description you could use something like:
  2701.  
  2702.         Restore ROOM*5+1000 : Rem Each ROOM has 5 data statements
  2703.         Read DESC$ : Print DESC$
  2704.             :            :
  2705.  
  2706. Obviously, if a data statement does not exist at the line specified by
  2707. RESTORE, and appropriate error message will be generated. Beware of
  2708. trying to use this command inside a procedure. In order to work, your
  2709. DATA statements *MUST* be within the current procedure.
  2710.  
  2711.  
  2712.  
  2713.                    WAIT (wait in 50ths of a second)                        258
  2714.  
  2715. WAIT n
  2716.  
  2717. Suspends an AMOS Basic program for n/50 of a second. Any functions
  2718. which use interrupts, such as MOVE and MUSIC, will continue to work as
  2719. normal during this period.
  2720.  
  2721.  
  2722.  
  2723.                  =TIMER= (count in 50ths of a second)
  2724.  
  2725. v=TIMER
  2726. TIMER=v
  2727.  
  2728. TIMER is a reserved variable which is incremented by 1 every 50th of a
  2729. second. It's commonly used to set the seed of the random number
  2730. generator like so:
  2731.  
  2732.         Randomize Timer
  2733.  
  2734.  
  2735.  
  2736.                       NOT (logical NOT operation)
  2737.  
  2738. v=NOT(d)
  2739.  
  2740. This function changes every binary digit in a number from a 1 to a 0
  2741. and vice versa. Since True=-1 (%1111111111111) in binary and False=0,
  2742. NOT(True)=False. Example:
  2743.  
  2744.         Print Bin$(Not(%1010),4)
  2745. ( result: 0101 )
  2746.         If Not(True)=False Then Print "False"
  2747.  
  2748.  
  2749.  
  2750.                           TRUE (logical TRUE)
  2751.  
  2752. v=TRUE
  2753.  
  2754. Whenever a test is made such as X>10, a value is produced. If the
  2755. condition is true then this number is set to -1, otherwise it will be
  2756. zero.
  2757.  
  2758.         If -1 Then Print "Minus 1 Is TRUE"
  2759.         If TURE Then Print "and TRUE Is ";TRUE
  2760.  
  2761.  
  2762.                          FALSE (logical FALSE)
  2763.  
  2764. v=FALSE
  2765.  
  2766. Returns a value of zero. This is used by all the conditional operations
  2767. such as IF...THEN and REPEAT...UNTIL to represent FALSE.
  2768.  
  2769.         Print FALSE
  2770. ( result : 0 )
  2771.  
  2772. 20: DISc ACCESS
  2773.  
  2774. The AMOS disc commands give you total access to the Amiga's filing
  2775. system. These can be exploited to create anything from a simple reader
  2776. to a fully fledged database.
  2777.  
  2778. Drives and volumes
  2779.  
  2780. As you know, the Amiga lets you label your discs in a number of
  2781. different ways. If you're unfamiliar with the CLI, you may find some of
  2782. these terms a little confusing. So I'll now provide you with a brief
  2783. explanation of the varoius naming conventions:
  2784.  
  2785.  
  2786. Drives
  2787. ------
  2788. Floppy Drives: Are assigned names in the following format
  2789.  
  2790.         DFn:
  2791.  
  2792. n is a single digit which holds the number of your drive. The first
  2793. floppy drive in your system (usually the internal drive) is known as
  2794. DF0: then comes drives DF1:, DF2: and DF3: if they're installed.
  2795.  
  2796. Hard drives: These are specified using:
  2797.  
  2798.         DHn:
  2799.  
  2800. Where n is the number of your hard drive (or a partition on it).
  2801.  
  2802.  
  2803. Volumes
  2804. -------
  2805. The Amiga also creates a separate VOLUME name for each individual disc.
  2806. Tihs label can be substituted for the drive name in any of your AMOS
  2807. Basic commands. AMOS will automatically check each available drive for
  2808. the required disc. If it can't be found, you'll get a "drive not
  2809. mounted" error.
  2810.  
  2811.   Whenever you prepare a new disc from the Workbench, the disc will be
  2812. assigned the name "Empty". To change this label from the WB, simply        261
  2813. click on the RENAME option and enter your new name in the dialogue box
  2814. provided. This name can be practically any string of characters you
  2815. like, but it must be terminated with a colon character when it's used
  2816. in your programs, just like the drive name. Here are some typical
  2817. volume names for you to examine:
  2818.  
  2819.         AMOS:
  2820.         AMOS_DATA:
  2821.  
  2822. WARNING! If you create several discs with the same name or swarp them
  2823. around indiscriminately, the Amiga can easily get confudsed as to which
  2824. disc you are actually referring to. In these circumstances, you'll need
  2825. to enter the drive name instead. This will tell AMOS precisely where
  2826. the required disc can be found on your system.
  2827.  
  2828.   You are strongly recommended to assign a different name to each and
  2829. every disc you use. This takes no more than a couple of secs from the
  2830. WB but it does simplify things enormously.
  2831.  
  2832.  
  2833. Logical devices
  2834. ---------------
  2835. Finally, there's also a set of objects known as logical devices. These
  2836. are used by the Amiga's operating routines to determine the precise
  2837. position of important systems files such has device handlers or fonts.
  2838. Each device is normally assigned to a specific directory on the current
  2839. start-up disc. Here are some examples used by AMOS.
  2840.  
  2841.         FONTS:  A directory containing the current fonts.
  2842.         LIBS:   Holds a library files required byt the AMOS SAY command.
  2843.  
  2844.  
  2845. Cross Dos
  2846. ---------
  2847. If you've bought the separate CROSS DOS package and installed it into
  2848. memory, you'll also be able to access IBM or ST format discs within
  2849. AMOS Basic. These discs are assigned names starting with letters DI.
  2850.  
  2851.         DIn:    (where n is the number of your drive)
  2852.  
  2853. In order to convert your STOS programs to AMOS Basic, you'll need to
  2854. save them in ASCII format using the FSAVE "*.ASC" option from STOS.
  2855. Then insert the disc into an Amiga floppy drive that has been mounted
  2856. by Cross-Dos as an IBM drive.
  2857.  
  2858.   Due to the differences between AMOS and STOS, many STOS progs will
  2859. require modifying slightly before they will run under AMOS.
  2860.  
  2861.  
  2862. Directory changing                                                         262
  2863. ==================
  2864.  
  2865.  
  2866.            DIR (print out the directory of the current disc)
  2867.  
  2868. DIR [PATH$] [/W]
  2869.  
  2870. Lists all the files on the current disc. If the optional path$ is
  2871. specified, only the files which satisfy a certain set of conditions
  2872. will be displayed. Any folders in the listing will be distinguished by
  2873. a leading "*" character.
  2874.  
  2875.   The listing can be halted at any time by pressing the spacebar. To
  2876. resume, simply press the spacebar once again.
  2877.  
  2878.   Note that if you change discs and try to get a directory listing, you
  2879. may be presented with a "device not mounted" error. This is because
  2880. you've removed the current disc without informing AMOS Basic. The
  2881. solution is to simply update the current directory name to the new
  2882. using a line like: DIR$="DF0:" before calling DIR
  2883.  
  2884.   /W lists the files in two columns across the screen. This effectively
  2885. doubles the number of files which can be displayed at any one time. The
  2886. path string consists of three main elements:
  2887.  
  2888.         [Disc:][Directory/] Filter.
  2889.  
  2890. Filter defines a set of conditions which should be satisfied for each
  2891. file in your listing.
  2892.  
  2893.    Normal Text: Each character in your text should match exactly one
  2894.                 character in the filename to be displayed. Example:
  2895.  
  2896.         Dir "Music"
  2897. ( result : Music )
  2898.  
  2899.    * (asterix): Match any list of letters in your filenames up to the      263
  2900.                 next control character.
  2901.  
  2902.  
  2903.         Dir "M*"
  2904.  
  2905. As a default, this option will ignore any files which include an MS-DOS
  2906. type extension. So a file lake: Mad.Asc  on the disc would not be
  2907. listed.
  2908.  
  2909.    . (period): Matches the extension of a filename. It's commonly used
  2910.                in conjunction with the "*" command to list all files
  2911.                with a particular extension.
  2912.  
  2913.    ? (question mark): Matchces a single character at the current
  2914.                       position.
  2915.  
  2916.  
  2917.  
  2918.                    =DIR$= (change current directory)
  2919.  
  2920. s$=DIR$
  2921. DIR$=s$
  2922.  
  2923. DIR$ contains the directory which will be used as the starting point
  2924. for all future disc operations, such as loading and saving. It's very
  2925. similar to the CD command from the CLI, with the added advantage of
  2926. allowing you to read the directory as well as just change it. Examples
  2927. of the usage:
  2928.  
  2929.         Print Dir$
  2930.         Dir$="AMOS:Iff/"
  2931.  
  2932.  
  2933.  
  2934.             PARENT (sets the current path up one directory)                264
  2935.  
  2936. PARENT
  2937.  
  2938. The action of PARENT is to load the current directory with the parent
  2939. of the present folder. By repeatedly using this command, you can
  2940. quickly get back to your original root directory.
  2941.  
  2942.  
  2943.  
  2944.                     SET DIR (set style used by DIR)
  2945.  
  2946. SET DIR n[,filter$]
  2947.  
  2948. Sets the style of your directory listings. n is the number of
  2949. characters ranging from 1-100 which will be displayed in each filename.
  2950. Note that this setting has NO effect on the actual length of your
  2951. names. It only changes the way they will be listed on the screen.
  2952.  
  2953.   "filter" is a list of pathnames which are to be EXCLUDED from your
  2954. directory searches. All filenames that match this filter are completely
  2955. ignored and will not be displayed as part of your directory. This can
  2956. be used to supress the annoying ".INFO" files which cointain the icon
  2957. definitions used by the WB. Note that it's possible to ignore a whole
  2958. list of filepaths at once. Simply terminate each name with a single "/"
  2959. character. As a default, the filter is set to:
  2960.  
  2961.         ".INFO/*.INFO/*.*.INFO"
  2962.  
  2963.  
  2964.  
  2965. Common disc operations                                                     265
  2966. ======================
  2967.  
  2968.  
  2969.                         DFREE (disc free space)
  2970.  
  2971. f=DFREE
  2972.  
  2973. Returns the amount of free space remaining in bytes on the current disc.
  2974.  
  2975.  
  2976.  
  2977.                         MKDIR (create a folder)
  2978.  
  2979. MKDIR f$
  2980.  
  2981. Creates a new folder on the disc with the name f$. Example:
  2982.  
  2983.         MkDir " Df0:TEST"
  2984.  
  2985.  
  2986.  
  2987.                    KILL (erase a file from the disc)
  2988.  
  2989. KILL f$
  2990.  
  2991. Deletes the file f$ from the current disc.
  2992.  
  2993.  
  2994.  
  2995.                         RENAME (rename a file)
  2996.  
  2997. RENAME old$ TO new$
  2998.  
  2999. Changs the name of a file.
  3000.  
  3001.  
  3002. Selecting a file                                                           266
  3003. ================
  3004.  
  3005.  
  3006.                         =FSEL$ (select a file)
  3007.  
  3008. f$=FSEL$(path$[,default$][,title1$,title2$])
  3009.  
  3010. This function lets you choose your files directly from the disc, using
  3011. the standard AMOS file selector.
  3012.  
  3013.   "path$" sets a search pattern which determines which files will be
  3014. displayed in your listing.
  3015.  
  3016.   After you've selected a file, FSEL$ will reuturn either its full
  3017. pathname, or an empty string "" if you selected QUIT.
  3018.  
  3019.   "default$" chooses a filename to be used as a default.
  3020.  
  3021.   "title1$" and "title2$" are optional text strings which describe a
  3022. title to be displayed at the top of your file selector. Example:
  3023.  
  3024.         F$=Fsel$("*.IFF","","Load an IFF File")
  3025.         If F$="" Then Edit : Rem Return to editor if no file was chosen.
  3026.         Load IFF F$,0
  3027.  
  3028.  
  3029. Running an AMOS program from disc
  3030. =================================
  3031.  
  3032.  
  3033.                   RUN (execute an AMOS Basic program)
  3034.  
  3035. RUN [file$]
  3036.  
  3037. Although it's easy enough to execute your progs straight from the
  3038. editor, we've also included a separate RUN command. This version of the
  3039. command without file$ can only be used from direct mode.
  3040.  
  3041.   But the RUN file$ statement may also be placed inside a Basic
  3042. program. This allows you to chain a list of programs together. Note
  3043. that when you run a program in this way, the existing program will be
  3044. removed from memory and any variables will be lost. Any data screens
  3045. that have been created though, will remain intact, thus allowing
  3046. intermediate loading screens to be displayed.
  3047.  
  3048.   This command is fantastically useful, as it allows you to split any
  3049. AMOS game into a number of levels which can be loaded separately from
  3050. the disc. Each level can now be writeen as a completely independent
  3051. program. So the only limit to the size of your games is the amount of
  3052. storage space on the disc! You can therefore produce some massive games
  3053. with this system!
  3054.  
  3055. See also PRUN
  3056.  
  3057.  
  3058. Checking for the existence of a file                                       267
  3059. ====================================
  3060.  
  3061.  
  3062.                 =EXIST (check if specified file exists)
  3063.  
  3064. flag=EXIST(f$)
  3065.  
  3066. EXIST checks the current directory for the file f$. If it's found, then
  3067. a value -1 will be returned, otherwise 0. This EXIST function is
  3068. capable of checking for the existence of anything from a single file to
  3069. an entire disc. Example:
  3070.  
  3071.         Print Exist("DF1:"): Rem Has a second drive been connected?
  3072.  
  3073.  
  3074.  
  3075.              =DIR FIRST$ (get first file in the directory
  3076.                          satisfying path name)
  3077.  
  3078. file$=DIR FIRST$(path$)
  3079.  
  3080. Returns a string containing the name and length of the first file on
  3081. the disc which satisfies the current search path$. WHen this function
  3082. is called, the entire directory listing will be loaded into memory. You
  3083. can now retrieve the name of the next file in the directory using a
  3084. call to the DIR NEXT$ function.
  3085.  
  3086.         Print Dir First$("*.*")
  3087.  
  3088.  
  3089.  
  3090.         =DIR NEXT$ (get the next file satisfying current path)
  3091.  
  3092. file$=DIR NEXT$
  3093.  
  3094. Returns the next filename in the directory listing created by a
  3095. previous DIR FIRST$ command. After the last item has been read from
  3096. this list, a string will be returned containing the empty string "".
  3097. The entire directory array will now be erased and the memory it
  3098. consumes will be released for the rest of your Basic program. Here's an
  3099. example which prints out all the files in the current directory:
  3100.  
  3101.         F$=Dir First$("*.*")
  3102.         While F$<>""
  3103.           Print F$ : Bell : Wait 30
  3104.           F$=Dir Next$
  3105.         Wend
  3106.  
  3107. See EXAMPLE 20.1 in the manual folder.
  3108.  
  3109.  
  3110. Disc files                                                                 268
  3111. ==========
  3112. Files are just collections of information which have been grouped
  3113. together in one place on the disc. Each file is assigned its own name
  3114. which may contain anything from 1 to 255 characters.
  3115.  
  3116.   Before you can use one of these files, you first need to initialize
  3117. it using either the OPEN IN, OPEN OUT, or APPEND instructions. When you
  3118. open a file, you assign it to a "channel" number ranging from one to
  3119. ten. This number will be used in all future disc operations to identify
  3120. the file you are currently working with. The commodore Amiga supports
  3121. two types of disc files: Sequential files and Random access files.
  3122.  
  3123.  
  3124. Sequential files
  3125. ================
  3126. Sequential files are the standard files which are used on the Amiga.
  3127. The reason for their name is that they only allow you to read your
  3128. information in the precise sequence it was originally created. This
  3129. means that if you wanted to change just one piece of the data in the
  3130. middle of a sequential file, you would have to read in the whole file
  3131. up and including this value, and then write the entire file back to the
  3132. disc.
  3133.  
  3134.   AMOS Basic allows you to access sequential files for either writing
  3135. or reading, but never for both at the same time.
  3136.  
  3137.         Open Out1,"file.seq"
  3138.         Input "What is your name";N$
  3139.         Print #1,N$
  3140.         Close 1
  3141.  
  3142. This creates a file called FILE.SEQ containing your name. In order to
  3143. read this information back from the file, type in the lines.
  3144.  
  3145.         Open In 1,"file.seq"
  3146.         Input #1,N$
  3147.         Print "I remember your name. It's ";N$
  3148.         Close 1
  3149.  
  3150. Notice how both these programs perform three separate operations:
  3151.  
  3152.  * Open the file using OPEN IN, OPEN OUT or APPEND
  3153.  * Access the file with INPUT# or PRINT#.
  3154.  * Close the file with CLOSE. Note that if you forget to do this, any
  3155.    changes to the file will be lost!
  3156.  
  3157. These three steps need to be completed in exactly this order, every
  3158. time you access a sequential file.
  3159.  
  3160.  
  3161.  
  3162.                    OPEN OUT (open a file for output)                       269
  3163.  
  3164. OPEN OUT channel,n$
  3165.  
  3166. Opens a sequential file for writing. If this file already exists it
  3167. will be erased. "channel" is a number between 1 and 10 and is used to
  3168. identify your new file in your subsequent PRINT# commands. n$ is the
  3169. name of the file to be opened.
  3170.  
  3171.  
  3172.  
  3173.                   APPEND (add some information to the
  3174.                          of an existing file)
  3175.  
  3176. APPEND channel,name$
  3177.  
  3178. Opens a sequential file for output. If this file exists, the new data
  3179. is added onto the end. This allows you to expand your files at any time
  3180. once they've been defined.
  3181.  
  3182.  
  3183.  
  3184.                     OPEN IN (open a file for input)
  3185.  
  3186. OPEN IN channel,f$
  3187.  
  3188. Sets up a file for reading. If this file doesn't exist, it will be
  3189. automatically created. "channel" is a number ranging from 1 to 10 which
  3190. is used by various INPUT instructions to refer to your open file.
  3191.  
  3192.  
  3193.  
  3194.                          CLOSE (close a file)
  3195.  
  3196. CLOSE n
  3197.  
  3198. Closes file number n. WARNING! If you forget to close a file after you
  3199. have finished with it, any changes you've made will be ignored!!
  3200.  
  3201.  
  3202.  
  3203.                   PRINT # (print a list of variables
  3204.                          to a file or device)
  3205.  
  3206. PRINT #channel,variable list
  3207.  
  3208. This command is identical to the normal print instruction, but instead
  3209. of displaying the information to the screen, it outputs it to a file or
  3210. output device specified by the channel number. Here's an example:
  3211.  
  3212.         Open Out 1,"TestFile"
  3213.         Print #,"Hello"
  3214.         Close 1
  3215.  
  3216. As with PRINT you can abbreviate PRINT # to ? #.
  3217.  
  3218.  
  3219.  
  3220.                   INPUT # (input a list of variables
  3221.                         from a file or device)
  3222.  
  3223. Reads information from either a sequential file or a device such as the    270
  3224. serial port. Like the standard INPUT command, it enters a list of
  3225. values and loads them into a set of Basic variables. As always, each
  3226. value in the list must be separated by a comma. Additionally, every
  3227. line of data also needs to be terminated by its own <line feed>
  3228. character. This is equivalent to the Return you pressed when you
  3229. entered a line from the keyboard.
  3230.  
  3231.  
  3232.  
  3233.                 LINE INPUT # (input a list of variables
  3234.                         not separated by a ",")
  3235.  
  3236. LINE INPUT #channel,variable list
  3237. LINE INPUT #channel,separators,variable list
  3238.  
  3239. This function is identical to INPUT #, except that it allows you to
  3240. separate your list of data using any character you with instead of the
  3241. standard comma. If the separator is omitted, it's automatically set to
  3242. the <return> character. When you're reading text, LINE INPUT # is
  3243. always the preferred choice. That's because the commas found in normal
  3244. English will be treated as a separator by the INPUT # command. This
  3245. will confuse your program completely.
  3246.  
  3247.  
  3248.  
  3249.                 SET INPUT (set End Of Line characters)
  3250.  
  3251. SET INPUT c1,c2
  3252.  
  3253. Sets the End-Of-Line chars which will be used to terminate a line of
  3254. data. The Amiga expects a single <line feed> at the end of each line,
  3255. whereas most other computers (including the ST) require both a Return
  3256. and <line feed>. SO if you try importing your ST files via the serial
  3257. cable, you'll end up with dozens of spurious Return characters in your
  3258. files. Fortunately you can  sidestep this problem using SET INPUT.
  3259.  
  3260.   c1 and c2 hold a pair of ASCII values which will be used for your
  3261. separators. If you want to use a single character ,simply load c2 with
  3262. a negative value such as minus one. Here's a couple of exmples:
  3263.  
  3264.         Set Input 10,-1 : Rem Standard Amiga Format
  3265.         Set Input 13,10 : Rem ST Format
  3266.  
  3267.  
  3268.  
  3269.            =INPUT$ (inputs a number of chars from a device)                271
  3270.  
  3271. X$=INPUT$ (f,count)
  3272.  
  3273. Reads "count" characters from device or file number f.
  3274.  
  3275.  
  3276.  
  3277.                       =EOF (test for end of file)
  3278.  
  3279. flag=EOF (channel)
  3280.  
  3281. EOF is a useful function which tests to see if the end of a file has
  3282. been reached at the current reading position. If it has, EOF returns a
  3283. result of -1, otherwise 0.
  3284.  
  3285.  
  3286.  
  3287.                        LOF (length of open file)
  3288.  
  3289. length=LOF(channel)
  3290.  
  3291. Returns the length of an open file. It makes no sense to use this
  3292. function in conjunction with devices other than the disc.
  3293.  
  3294.  
  3295.  
  3296.                      POF (variable holding current
  3297.                        position of file pointer)
  3298.  
  3299. pos=POF(channel)
  3300.  
  3301. The POF function changes the current reading or writing position of an
  3302. open file, for example:
  3303.  
  3304.         Pof(1)=1000
  3305.  
  3306. This sets the read/write position to 1'000 characters past the start of
  3307. the file. Oddly enough POF can be used in this way to provide a crude
  3308. form of random access when using sequential files! The reason this
  3309. works is simply that disc drives are inherently random and all
  3310. sequential operations are effectively simulated using random access.
  3311.  
  3312.  
  3313.  
  3314. Random access files
  3315. ===================
  3316. Random access files are so called because you can access the
  3317. information stored on the disc in any random order you like. In order
  3318. to use these files you first need to understand a little bit of theory.
  3319.  
  3320.   All random access files are composed of units called records, each
  3321. with their own unique number. These records are in turn split up into a
  3322. number of separate fields. Every field contains one individual piece of
  3323. information. When you use sequential files, these fields can be any
  3324. length you with, as the file will only be read in one direction. Random
  3325. access files, however, always require you to specify the maximum size
  3326. of these fields in advance.
  3327.  
  3328.   Supposing you wanted to produce a file containing a list of names and
  3329. telephone numbers. In this case you could use the fields:
  3330.  
  3331.         Field           Max length                                         272
  3332.         -----           ----------
  3333.         SURNAME$             15
  3334.         NAME$                15
  3335.         CODE$                10
  3336.         TEL$                 10
  3337.  
  3338. You could now define these fields using a line like:
  3339.  
  3340.         Field #1,15 as SURNAME$,15 as NAME$,10 as CODE$,10 as TEL$
  3341.  
  3342. It's important to realize that the strings specified by the FIELD
  3343. instruction can also be used as normal string variables. This allows
  3344. you to read and write information to any particular field. For example:
  3345.  
  3346.         SURNAME$="HILL"
  3347.         TEST$=SURNAME$ : Print TEST$
  3348.  
  3349. After you've loaded your record with information, you can write it onto
  3350. the disc using PUT command. Example:
  3351.  
  3352.         Put 1,10
  3353.  
  3354. Loads data into record 10 of the file opened on channel 1
  3355.  
  3356.   Similarly, you can read a record using the GET instruction:
  3357.  
  3358.         Get 1,10
  3359.  
  3360.  
  3361.  
  3362.              OPEN RANDOM (open a channel to a random file)
  3363.  
  3364. OPEN RANDOM channel,n$
  3365.  
  3366. Opens a random access file called n$ on the current disc. When you're
  3367. using this instruction, you should always define the record sturcture
  3368. immediately afterwards using the FIELD$ command.
  3369.  
  3370.  
  3371.  
  3372.                     FIELD (define record structure)
  3373.  
  3374. FIELD channel,length1 AS field1$,length2 AS field2$......
  3375.  
  3376. FIELD allows you to define a record which will be used for a random
  3377. access file. This record can be up to 65535 bytes in length.
  3378.  
  3379.         Field 1,15 as SURNAME$,15 as NAME$,10 as CODE$,10 as TEL$
  3380.  
  3381.  
  3382.  
  3383.               PUT (output a record to random access file)                  273
  3384.  
  3385. PUT channel,r
  3386.  
  3387. PUT moves a record from memory into record number r of a random access
  3388. file. Before use, the contents of the new record should first be placed
  3389. in the field strings defined by FIELD, using a statement such as:
  3390.  
  3391.         SURNAME$="HILL"
  3392.  
  3393. Although you can write existing records in any order you like, you're
  3394. not allowed to scatter records on the disc totally at random. This
  3395. means that if you have just created a file you can't type in something
  3396. like:
  3397.  
  3398.         Put 1,1
  3399.         Put 1,5
  3400.  
  3401. In this case, the PUT 1,5 instruction will generate an error, as there
  3402. are no records in the file with numbers between 2 and 5. Record 2 must
  3403. be the next new record in the file, then 3,4... example:
  3404.  
  3405.         Open Random 1,"TELEPHONE"
  3406.         Field 1,30 As NAME$, 30 As Tel$
  3407.         INDEX=1
  3408.         Do
  3409.           Input "Enter a name";NAME$
  3410.           Exit If NAME$=""
  3411.           Input "Enter telephone number";TEL$
  3412.           Put 1,Index : Inc INDEX
  3413.         Loop
  3414.         Close 1
  3415.  
  3416.  
  3417.  
  3418.             GET (input a record from a random access file)
  3419.  
  3420. GET channel,r
  3421.  
  3422. Reads record number r stored in a random access file opened using OPEN.
  3423. It then loads this record into the field strings created by FIELD. The
  3424. strings can now be manipulated in the normal way. Note that you can
  3425. only use GET to retrieve records which are actually on the disc. If you
  3426. try to grab a record number which does not exist then an error will be
  3427. generated. Example:
  3428.  
  3429.         Open Random 1,"TELEPHONE"
  3430.         Field 1,30 As NAME$, 30 As TEL$
  3431.         Do
  3432.           Input "Enter Record number";INDEX
  3433.           Exit If Index=0
  3434.           Get 1,INDEX : Print NAME$ : Print TEL$
  3435.         Loop
  3436.         Close 1
  3437.  
  3438.  
  3439. The Printer                                                                274
  3440. ===========
  3441.  
  3442.  
  3443.                     LLIST (print a part or all of a
  3444.                          program on a printer)
  3445.  
  3446. LLIST
  3447.  
  3448. Lists the entire program straight to the printer. Try listing some of
  3449. the Basic programs supplied on the DATA disc. These provide a perfect
  3450. demonstration of the various programming tehcniques neeked to write
  3451. your own AMOS Basic games. Feel free to modify them as much as you
  3452. like.
  3453.  
  3454.  
  3455.  
  3456.                        LPRINT (output a list of
  3457.                        variables to the printer)
  3458.  
  3459. LPRINT variable list
  3460.  
  3461. This is exactly the same as PRINT but sends your data to the printer
  3462. instead of the screen. Example:
  3463.  
  3464.         Lprint "Hello"
  3465.  
  3466. See PRINT, USING, PRINT #
  3467.  
  3468.  
  3469.  
  3470.                 LDIR (list a directory to the printer)
  3471.  
  3472. LDIR [PATH$] [W/]
  3473.  
  3474. Lists the directory of the current disc to the printer. See DIR for
  3475. more details.
  3476.  
  3477.  
  3478. External devices
  3479. ================
  3480.  
  3481.  
  3482.                OPEN PORT (open a channel to an I/O port)
  3483.  
  3484. OPEN PORT channel,"PAR:"  (open a channel to the Paraller interface)
  3485. OPEN PORT channel,"SER:"  (open a channel to the RS232 port)
  3486. OPEN PORT channel,"PRT:"  (open a channel for the printer)
  3487.  
  3488. OPEN PORT allows you to communicate with external devices such as the
  3489. RS232 port. All the standard file commands can be performed as normal,
  3490. except for commands like LOF or POF which are obviously only relevant
  3491. to disc operations. Example:
  3492.  
  3493.         Open Port 1,"SER:"                                                 275
  3494.         For X=0 To 10
  3495.           Print #1,"AMOS BASIC"
  3496.         Next X
  3497.         Close 1
  3498.  
  3499. This program prints out ten lines of text on the device connected to
  3500. the RS232 port. If your printer uses the paraller port change line 10
  3501. to:
  3502.  
  3503.         Open Port 1,"PRT:"
  3504.  
  3505. Similarly you can input information from a device such as a modem with
  3506. a line like:
  3507.  
  3508.         Input #1,A$ : Print A$
  3509.  
  3510. When accessing these external devices all the normal input statements
  3511. are available for your use, including INPUT$ and LINE INPUT.
  3512.  
  3513.  
  3514.  
  3515.             =PORT (function to test if channel is waiting)
  3516.  
  3517. n=PORT(channel)
  3518.  
  3519. Tests to see if an input device is ready to send you some information.
  3520. If the device is waiting for you to read it, a value of -1 will be
  3521. returned by this function, otherwise 0 (false).
  3522.  
  3523.  
  3524.  
  3525.  
  3526.  
  3527.  
  3528.  
  3529.  
  3530.                          21: SCREEN COMPACTION                             276
  3531.                       ---------------------------
  3532.  
  3533.  
  3534.                        SPACK (screen compaction)
  3535.  
  3536. SPACK s TO n [tx,ty,bx,by]
  3537.  
  3538. The SPACK command packs screen s into memory bank n. Everything about
  3539. the current image is saved, including its mode, screen size, offset and
  3540. display position. This allows you to recreate your screen in exactly
  3541. its original state.
  3542.  
  3543.   s is the number of the screen which contains yur image. n holds the
  3544. number of a memory bank from 1-16. If this bank doesn't currently
  3545. exist, it will be reserved for you automatically. Your new bank will be
  3546. stored in FAST memory if it's available, and will be saved along with
  3547. our Basic program. After you've called this function, the size of your
  3548. screen can be found using LENGTH. Example:
  3549.  
  3550.         F$=FSEL$("*","","Load a picture")
  3551.         Load Iff F$,0
  3552.         Spack 0 To 1
  3553.         Print "The length of your new bank is ";Length(1);" Bytes"
  3554.         Wait Key
  3555.         Screen Close 0
  3556.         UnPack 1 To 0 : Rem recreate compacted screen
  3557.  
  3558. You don't, of course have to compact an entire screen with this
  3559. instruction. The optional parameters let you compress any rectangular
  3560. section of the display you like.
  3561.  
  3562.   tx,ty now hold the coordinates of the top left corner of this region.
  3563. bx,by set the position of the bottom right corner. All x coordinates
  3564. are rounded to the nearest 8 pixel boundary.
  3565.  
  3566.   Note that in order to achieve the maximum memory reduction, SPACK
  3567. will attempt to compact your image using several different strategies.
  3568. It will then compress your image using the method which consumes the
  3569. least amount of memory. One side effect of this efficiency, is that it
  3570. usually takes around 6 secs to compress one of your images. This is        277
  3571. hardly a disadvantage however, as normally the compaction is only
  3572. required when you are writing your programs.
  3573.  
  3574.   Since each image can be unpacked on the screen in less than a second,
  3575. there's no risk of interference with the speed of your games. It speeds
  3576. is of the essence though, you may wish to use the CBLOCK system
  3577. instead. See the section on Background Graphics for more details.
  3578.  
  3579.   Incidentally, if you compare the compacted size of your files with
  3580. their original length on the disc, you may be mislead into
  3581. underestimating the size of the memory reduction. It's important to
  3582. realize that the vast majority of these files have ALREADY BEEN
  3583. COMPESSED using the standard IFF compaction routines. So it's rather
  3584. surprising that AMOS can reduce them by a further 20 % !
  3585.  
  3586.   Compacted screens are perfect for the titles and hi-score tables
  3587. required in an arcade game, as they allow you to introduce snazzy
  3588. screen effects without consuming enormous quantities of memory. They
  3589. can also be incorporated directly into RPGs and Adventures.
  3590.  
  3591.  
  3592.  
  3593.                          PACK (pack a screen)
  3594.  
  3595. PACK s TO n [tx,ty,bx,by]
  3596.  
  3597. Compresses screen s into bank number n. Unlike the previous SPACK
  3598. command, only the image data is compressed. So your compacted screen
  3599. must always be unpacked directly into an existing screen.
  3600.  
  3601.   Because of the way images are decompressed, there will be a
  3602. noticeable shimmer effect unless you've previously double buffered your
  3603. screens. Try to avoid using PACK with single buffered screens. It's
  3604. much more sensible to call the SPACK system for this purpose.
  3605.  
  3606.   If the optional coordinates are included, only a section of the image
  3607. will be compressed.
  3608.  
  3609.   Since PACK is fully compatible with the standard AUTOBACK system,
  3610. it's easy to combine compacted images with moving screens. If you are
  3611. using Autoback 2  mode, you'll even be able to unpack your images
  3612. BEHIND existing bobs. It's therefore possible to exploit this
  3613. instruction in conjunction with SCREEN OFFSET to create fantastic
  3614. scrolling backgrounds for your games.
  3615.  
  3616.  
  3617.  
  3618.                   UNPACK (unpack a compacted screen)
  3619.  
  3620. Decompresses a screen which has been previously compacted using the
  3621. SPACK or PACK instructions. Each compaction routine has its own
  3622. specifix form of the UNPACK command.
  3623.  
  3624.  SPACK
  3625.  -----
  3626.  
  3627. UNPACK b TO s
  3628.  
  3629. Opens a screen s and restores the compacted screen into bank b. If this
  3630. screen already exists, it will completely replaced by the new image.
  3631. Once the screen has been unpacked, it will be neatly flicked into view.    278
  3632.  
  3633.  PACK
  3634.  ----
  3635.  
  3636. PACKed screens can be unpacked using two separate instructions. These
  3637. take an image from a memory bank, and load it straight into an existing
  3638. screen. WARNING! The destination screen MUST be in exactly the same
  3639. format as your compacted picture, otherwise you'll get an
  3640. "illegal function call" error.
  3641.  
  3642.   When you unpack your screens, you may notice that the effect is
  3643. slightly messy. That's 'cause the PACK command is only really intended
  3644. for use with the double buffering system. Providing your screen is
  3645. double buffered, you'll get a delightfully smooth result.
  3646.  
  3647. UNPACK b
  3648.  
  3649. Unpacks the screen at its original position
  3650.  
  3651. UNPACK b,x,y
  3652.  
  3653. Redraws your image starting at coordinates x,y. If the new image
  3654. doesnt' fit into the current screen, you'll get an error message.
  3655.  
  3656.  
  3657.  
  3658.  
  3659.  
  3660.  
  3661.  
  3662.  
  3663.  
  3664.                            22: MACHINE CODE                                279
  3665.                       ---------------------------
  3666.  
  3667. Number conversion
  3668. -----------------
  3669.  
  3670.                      =HEX$ (convert number to hexadecimal)
  3671.  
  3672. h$=HEX$(v)
  3673. h$=HEX$(v,n)
  3674.  
  3675. HEX$ converts the integer v into hexadecimal notation (base 16). It
  3676. returns a sequence of n hexadecimal characters in the string h$. Example:
  3677.  
  3678.         Print Hex$(Colour(1),3)
  3679.  
  3680.  
  3681.  
  3682.                     =BIN$ (convert number to binary string)
  3683.  
  3684. b$=BIN$(v)
  3685. b$=BIN$(v,n)
  3686.  
  3687. Converts a number into binary notation (base 2).
  3688.  
  3689.  
  3690. Memory manipulation
  3691. -------------------
  3692.  
  3693.  
  3694.                             =PEEK (get byte address)
  3695.  
  3696. v=PEEK(address)
  3697.  
  3698. Returns the 8-bit byte stored at "address"
  3699.  
  3700.  
  3701.  
  3702.                          POKE (change byte at address)                     280
  3703.  
  3704. POKE address,v
  3705.  
  3706. Copies the number v into "address". v must always lie in the range 0-255.
  3707. Be warned: POKE can be very dangeroud. If you poke around
  3708. indiscriminately, you will almost certainly crash the Amiga!
  3709.  
  3710.  
  3711.  
  3712.                           =DEEK (get word at address)
  3713.  
  3714. v=DEEK(address)
  3715.  
  3716. Reads the two-byte word found at "address". "address" MUST be even or
  3717. an address error will occur.
  3718.  
  3719.  
  3720.  
  3721.                          DOKE (change word at address)
  3722.  
  3723. DOKE address,value
  3724.  
  3725. DOKE loads a two-byte number between 0 and 65535 into the memory location
  3726. at "address". In knowledgeable hands this function caan be very useful.
  3727. Since even the best of us make mistakes however, you should always save
  3728. a copy ot your progs to the disc before attempting to use this function
  3729. in a new routine. Example:
  3730.  
  3731.         Doke Phybase(1)+1000,65535
  3732.  
  3733.  
  3734.  
  3735.                       =LEEK (read a long word at address)
  3736.  
  3737. v=LEEK(address)
  3738.  
  3739. Returns the four-byte long word stored at "address". Like DEEK, the
  3740. address used with this function must always be EVEN. If bit 31 of
  3741. the return value is set to 1, v will be diplsyed as a negative
  3742. number. This isn't a bug. It's just a side effect of the way AMOS
  3743. deals with numbers.
  3744.  
  3745.  
  3746.  
  3747.                        LOKE (change long word at address)                  281
  3748.  
  3749.  
  3750. LOKE address,n
  3751.  
  3752. LOKE copies the four-byte number into "address". Example:
  3753.  
  3754.         Loke Phybase(1)+10000,$FFFFFFFF
  3755.  
  3756. Indiscriminate use of this function can lead to the Amiga crashing
  3757. horribly, so take care.
  3758.  
  3759.  
  3760.  
  3761.                       =VARPTR (get address of a variable)
  3762.  
  3763. address=VARPTR(variable)
  3764.  
  3765. Returns the address in memory of a Basic variable. Each type of variable
  3766. is stored using its own individual format:
  3767.  
  3768. Integers: VARPTR finds the address of the four bytes containing the
  3769. contents of your variable.
  3770.  
  3771. Floating points: VARPTR returns the location of four bytes which hold
  3772. the value of the variable in the IEEE single precision format
  3773.  
  3774. Strings: The VARPRT address points to the first character of the string.
  3775. Since AMOS Basic doesn't end its strings with a CHR$(0), you must
  3776. obtain the length of the string using something like:
  3777.  
  3778. DEEK(VARPTR(A$)-2), where A$ is the name of your variable. You could
  3779. also use LEN(A$) of couse.
  3780.  
  3781.  
  3782.  
  3783.                            COPY (copy a memory block)
  3784.  
  3785. COPY start,finish TO destination
  3786.  
  3787. This command is used to rapidly move large sections of the Amiga's
  3788. memory from one place to another. "start" and "finish" are the
  3789. addresses of the first and last bytes of your data respectively.
  3790.  
  3791.   "destination" points to a memory area which will be loaded with
  3792. your new data. All these addresses MUST be even, or you'll get an
  3793. address error.
  3794.  
  3795.  
  3796.  
  3797.                     FILL (fill memory block with a longword)               282
  3798.  
  3799. FILL start TO finish, pattern
  3800.  
  3801. Fills a selected region of memory with the four bytes held in
  3802. "pattern". "start" and "finish" determine the position and size of
  3803. the block which is to be filled. These addresses MUST BE EVEN!
  3804.  
  3805.   "pattern" is a long word containg a four byte fill pettern. This
  3806. will be copied into each group of memory locations between
  3807. "start" and "finish".
  3808.  
  3809.  
  3810.  
  3811.                         =HUNT (find a string in memory)
  3812.  
  3813. f=HUNT(start TO finish, s$)
  3814.  
  3815. Searches through the Amiga's memory for the sequence of characters held
  3816. in s$. "start" is the address of the first byte in memory to be searched,
  3817. and "finish" is the address of the last. On completion, f will hold
  3818. either 0 (in the string in a$ was not found) or the location of f$.
  3819.  
  3820.  
  3821.  
  3822. Bitwise operations
  3823. ------------------
  3824.  
  3825.  
  3826.                                ROL (rotate left)
  3827.  
  3828. ROL.B n,v
  3829. ROL.W n,v
  3830. ROL.L n,v
  3831.  
  3832. ROL is a Basic version of the ROL instruction found in 68000 assembly
  3833. language. The effect is to take the binary representation of a number
  3834. in v, and rotate it left by exactly n places.
  3835.  
  3836.   If v is a single variable, then the number to be rotated is taken
  3837. directly from v. But if v is an expression, then it's treated as the
  3838. address of your number instead. Example:
  3839.  
  3840.         A=8
  3841.         Ror 1,A
  3842.         Print A
  3843. ( result: 4 )
  3844.  
  3845. ROR is capable of dividing any positive value by a power of two. The
  3846. resulting calculation will be performed much faster than the equivalent
  3847. "/" operation.
  3848.  
  3849.  
  3850.  
  3851.  
  3852.                                ROR (rotate right)                          283
  3853.  
  3854. This is very similar to ROL but rotates the number in the opposite
  3855. direction.
  3856.  
  3857.  
  3858.  
  3859.                                =BTST (test a bit)                          284
  3860.  
  3861. Tests the binary digit at position n in the variable v. If v is an
  3862. expression, it will be used as the address of the bit which is to
  3863. be checked. In this case n will be automatically ANDed with 7
  3864. before proceeding.
  3865.  
  3866.   After BTST has been called, b will be loaded with -1 if the bit
  3867. at position n is set to 1, otherwise it will be 0.
  3868.  
  3869.  
  3870.  
  3871.                              BSET (set a bit to 1)
  3872.  
  3873. BSET n,v
  3874.  
  3875. Sets the bit at position n to 1 in the variable v.
  3876.  
  3877.  
  3878.  
  3879.                               BCHG (change a bit)
  3880.  
  3881. BCHG n,v
  3882.  
  3883. Changes bit number n in the variable v. If this bit is currently 1
  3884. then the new value will be a zero, and vice versa.
  3885.  
  3886.  
  3887.  
  3888.                                BCLR (clear a bit)                          285
  3889.  
  3890. BCLR n,v
  3891.  
  3892. Clears bit number n in variable v by setting it to zero. Like all
  3893. the bitwise operations, if v is an expression, then it will be used
  3894. as the location of your data in memory.
  3895.  
  3896.  
  3897.  
  3898. Using assembly language
  3899. -----------------------
  3900. AMOS Basic includes special facilities which allow you to combine
  3901. assembly language routines with your Basic programs. It's worth
  3902. emphasising that, because of the sheer power of the AMOS system,
  3903. machine code is only rarely useful. We've added these features solely
  3904. for existing assembly language programmers who may wish to optimize
  3905. their Basic programs with the occasional bit of machine code.
  3906.  
  3907.  
  3908.  
  3909.                    PLOAD (reserve a memory bank for
  3910.                           some machine code)
  3911.  
  3912. PLOAD "filename",bank
  3913.  
  3914. Reserves a memory bank and loads it with a machine-code program from
  3915. the disc. "bank" is the number of a memory bank which is to be reserved
  3916. for your program. If it's negative, then the bank will be calculated
  3917. using the absolute value of this number, and the required memory area
  3918. will be allocated from CHIP mem.
  3919.  
  3920.   Once you've loaded a program in this way, you can save it on the disc
  3921. as an normal ".ABK" file. Since the banks created by this function are
  3922. permanent, it will also be saved directly with your AMOS programs.
  3923.  
  3924.   Your program must consist of a machine code file in the standard
  3925. Amiga format. In practice, it can contain practically anything you
  3926. like, with the following restrictions:
  3927.  
  3928.  * The code MUST be totally relocatable.
  3929.  * Only the CODE chunck of your program will be loaded
  3930.  * The program must be terminated by a single RTS instruction
  3931.  
  3932.  
  3933.  
  3934.                   CALL (call a machine-code program)
  3935.  
  3936. CALL address[,params]
  3937. CALL bank[,params]
  3938.  
  3939. Executes an assembly language program held in the AMiga's memory.
  3940.  
  3941.   "addrss" can be either the absolute location of your code, or the
  3942. number of an AMOS memory bank which has been previously created with
  3943. PLOAD.
  3944.  
  3945.   On entry to your program, registers D0 to D7 and A0 to A2 will be
  3946. loaded from the values stored in the DREG and AREG arrays. Your
  3947. assembly language program can now change any 68000 register it likes.
  3948. At the start the routine, register A3 will point to the optional
  3949. parameter list, and A5 will contain the address of the main AMOS data
  3950. area. When your program's finished, you can return to Basic with just a
  3951. simple RTS instruction.
  3952.  
  3953.   "params" is a list of parameters which will be pushed onto the A3
  3954. stack by the CALL command. These parameters need to be removed in
  3955. REVERSE order. So the last value you entered into the instruction wlil
  3956. be the first on to the stack. Depending on the type of your parameters,
  3957. the values referenced by A3 will be in one of the following three
  3958. formats:
  3959.  
  3960. Integer : Holds a long word containing a normal AMOS integer.
  3961.  
  3962. F.Point : Contains a floating point number in IEEE single prec. format.
  3963.  
  3964. String  : Sotres the address of the string. All strings start with a
  3965.           single word containing their length.
  3966.  
  3967. WARNING! Never poke directly into a string! When a string is
  3968. initialised to a constant the string address will point to the original
  3969. assignment statement inside the current program listing! So if you
  3970. change this value, you'll affect your original source code. This is
  3971. obviously extremely unwise, and should be avoided. See EXAMPLE 21.1
  3972.  
  3973.  
  3974.  
  3975.                =AREG= (variable used to pass information                   286
  3976.                    to the 68000's address registers)
  3977.  
  3978. a=AREG(r)
  3979. AREG(r)=a
  3980.  
  3981. AREG is an array of six PSEUDO variables which are used to hold a copy
  3982. of the first six of the 68000's address registers. r can range from 0
  3983. to 6 and indicates the number of the address register which is to be
  3984. affected.
  3985.  
  3986.   Whenever the CALL command is executed, the contents of this array are
  3987. loaded automatically into address registers A0 to A2. At the end of the
  3988. function, they are then saved back with any new information which has
  3989. been placed in the appropriate registers.
  3990.  
  3991.  
  3992.  
  3993.                =DREG= (variable used to pass information
  3994.                     to the 68000's data registers)
  3995.  
  3996. d=DREG(r)
  3997. DREG(r)=d
  3998.  
  3999. This is an array of eight integers wihch holds a copy of the contents
  4000. of the 68000 data registers. r refers to the register number and can
  4001. range from 0 to 7 for D1 to D7 respectively.
  4002.  
  4003.  
  4004. Accessing the system libraries                                             287
  4005. ==============================
  4006. AMOS also allows you to call up most of the Amiga's internal system
  4007. libraries directly from the ROM. These aren't particularly useful,
  4008. since all the really interesting calls have already been built into
  4009. AMOS!
  4010.  
  4011.   Don't use these routines unless you know precisely what you're doing.
  4012. The Amiga is notoriously difficult to program, and it's all to easy to
  4013. crash the system and generate the infamous GURU error by mistake.
  4014.  
  4015.  
  4016.  
  4017.                         =DOSCALL (DOS library)
  4018.  
  4019. r=DOSCALL(function)
  4020.  
  4021. Executes a function directly from the DOS library. "function" is the
  4022. offset to the appropriate function. See the Amiga ROM Kernel Manuals
  4023. for more details.
  4024.  
  4025.   Before using this function, you'll need to set some of the control
  4026. registers in D0 to D7 and A0 to A2 using the AREG and DREG functions.
  4027. WHen the routine exits back to Basic, the contents of D0 are returned
  4028. in r. Note: The return values will not be loaded into DREG and AREG.
  4029.  
  4030.  
  4031.  
  4032.                         =EXECALL (EXEC library)
  4033.  
  4034. r=EXECALL(function)
  4035.  
  4036. Performs a call to the Amiga's EXEC library. On entry, D0 to D7 and
  4037. A0 to A2 are loaded with the control settings from the DREG and AREG
  4038. arrays. r is returned holding the contents of D0.
  4039.  
  4040.  
  4041.  
  4042.                       =GFXCALL (Graphics library)
  4043.  
  4044. r=GFXCALL(function)
  4045.  
  4046. Calls a routine from the graphics library using the control values
  4047. stored in the DREG and AREG arrays.
  4048.  
  4049.  
  4050.  
  4051.                      =INTCALL (Intuition library)
  4052.  
  4053. r=INTCALL(function)
  4054.  
  4055. Executes a command from the Intuition library. As usual the control
  4056. values are loaded from DREG and AREG arrays, and r holds the result of
  4057. the call.
  4058.  
  4059.   Since AMOS doesn't use the standard intuition routine, this function
  4060. is especially dangerous. Only call it if you are already familiar with
  4061. the Amiga's intuition library.
  4062.  
  4063.  
  4064. Inside AMOS Basic                                                          288
  4065. =================
  4066. In order to provide full access to the inner workings of the AMOS
  4067. system for developers, we've included several "hooks" into the various
  4068. data areas. These are not intended for the casual programmer, but they
  4069. do enable adbanved users to create their own AMOS utilities.
  4070.  
  4071.  
  4072.  
  4073.                     =SCREEN BASE (get screen table)
  4074.  
  4075.  
  4076. table=SCREEN BASE
  4077.  
  4078. Returns the base address of the internal table used to hold the number
  4079. and position of your AMOS screens. See EXAMPLE 21.2
  4080.  
  4081.  
  4082.  
  4083.                     =SPRITE BASE (get sprite table)
  4084.  
  4085. table=SPRITE BASE(n)
  4086.  
  4087. Provides the address of the internal data list for sprite n. If this
  4088. sprite doesn't exist, then the address of the table will be zero.
  4089.  
  4090.   Negative values for n return the address of the optional MASK
  4091. associated with your sprite. "table" will now contain one of three
  4092. possible values, depending on the status of this mask:
  4093.  
  4094. table < 0   Indicates that there's no mask for this sprite at all
  4095. table = 0   Sprite n does have a mask, but it hasn't been generated
  4096. table > 0   This is the address of the Mask in memory. The first
  4097.             long word of this area holds the length of the mask, and
  4098.             the next is followed by the actual definition.
  4099.  
  4100. See EXAMPLE 21.3
  4101.  
  4102.  
  4103.  
  4104.                        =ICON BSE (get icon base)
  4105.  
  4106. table=ICON BASE(n)
  4107.  
  4108. Returns the address for icon n. The format of this information is
  4109. exactly the same as the previous SPRITE BASE function.
  4110.  
  4111.  
  4112.  
  4113.  
  4114.  
  4115.  
  4116.  
  4117.  
  4118.  
  4119.                            23: COMMAND INDEX                               289
  4120.                       ---------------------------
  4121.  
  4122. ABS ..................125       ACOS .................112
  4123. ADD .................. 39       AMAL .................186
  4124. AMAL FREEZE ..........193       AMAL ON/OFF ..........193
  4125. AMALERR ..............195       AMPLAY ...............193
  4126. AMREG ................193       ANIM .................205
  4127. ANIM FREEZE ..........206       ANIM ON/OFF ..........206
  4128. APPEAR ...............136       APPEND ...............269
  4129. AREG .................286       ASC .................. 58
  4130. AT ................... 91       ATAN .................113
  4131. AUTO VIEW ON/OFF .....121       AUTOBACK .............158
  4132. BANK TO MENU .........221       BAR .................. 68
  4133. BCHG .................284       BCLR .................285
  4134. BELL .................234       BGRAB ................ 31
  4135. BIN$ .................279       BLOAD ................ 51
  4136. BOB ..................155       BOB CLEAR ............161
  4137. BOB COL ..............170       BOB DRAW .............161
  4138. BOB OFF ..............163       BOB UPDATE ...........161
  4139. BOBSPRITE COL ........170       BOOM .................233
  4140. BORDER ...............101       BORDER$ .............. 98
  4141. BOX .................. 65       BREAK ON/OFF ......... 83
  4142. BSAVE ................ 51       BSET .................284
  4143. BTST .................284       CALL .................285
  4144. CDOWN ................ 93       CDOWN$ ............... 93
  4145. CENTRE ............... 96       CHANAN ...............195
  4146. CHANGE MOUSE .........165       CHANMV ...............195
  4147. CHANNEL ..............197       CHOICE ...........214,216
  4148. CHR$ ................. 58       CIRCLE ............... 66
  4149. CLEAR KEY ............251       CLEFT ................ 94
  4150. CLEFT$ ............... 94       CLINE ................ 96
  4151. CLIP ................. 71       CLOSE ................269
  4152. CLOSE EDITOR ......... 30       CLOSE WORKBENCH ...... 30
  4153. CLS ..................131       CLW ..................103
  4154. CMOVE ................ 90       COL ..................170
  4155. COLOUR ............... 62       COP LOGIC ............144
  4156. COP MOVE .............143       COP MOVEL ............143
  4157. COP RESET ............144       COP WAIT .............143
  4158. COPPER OFF ...........143       COPPER ON ............143
  4159. COPY .................281       COS ..................112
  4160. CRIGHT ............... 94       CRIGHT$ .............. 94
  4161. CUP .................. 93       CUP$ ................. 93
  4162. CURS ON/OFF .......... 95       CURS PEN ............. 96
  4163. DATA .................256       DEC .................. 39
  4164. DEEK .................280       DEF FN ...............118                  290
  4165. DEF SCROLL ...........133       DEFAULT ..............121
  4166. DEFAULT PALETTE ......131       DEGREE ...............111
  4167. DEL BLOCK ............210       DEL CBLOCK ...........211
  4168. DEL ICON .............209       DEL WAVE .............244
  4169. DFREE ................265       DIM .................. 36
  4170. DIR ..................262       DIR FIRST$ ...........267
  4171. DIR NEXT$ ............267       DIR$ .................263
  4172. DIRECT ............... 80       DO...LOOP ............ 79
  4173. DOKE .................280       DOSCALL ..............287
  4174. DOUBLE BUFFER ........156       DRAW ................. 65
  4175. DREG .................286       DUAL PLAYFIELD .......127
  4176. DUAL PRIORITY ........128       EDIT ................. 80
  4177. ELLIPSE .............. 66       END .................. 81
  4178. EOF ..................271       ERASE ................ 50
  4179. ERRN ................. 86       ERROR ................ 86
  4180. EVERY n GOSUB ........ 82       EVERY n PROC ......... 82
  4181. EVERY ON/OFF ......... 82       EXECALL ..............287
  4182. EXIST ................267       EXIT ................. 79
  4183. EXIT IF .............. 80       EXP ..................114
  4184. FADE .................137       FALSE ................259
  4185. FIELD ................272       FILL .................383
  4186. FIRE .................169       FIX ..................117
  4187. FLASH ................138       FLIP$ ................ 57
  4188. FN ...................118       FONT$ ................107
  4189. FOR...NEXT ........... 77       FREE ................. 53
  4190. FSEL$ ................266       GET ..................273
  4191. GET BLOCK ............209       GET BOB ..............163
  4192. GET CBLOCK ...........211       GET DISC FONTS .......107
  4193. GET FONTS ............106       GET ICON .............208
  4194. GET ICON PALETTE .....208       GET PALETTE ..........131
  4195. GET ROM FONTS ........107       GET SPRITE ...........107
  4196. GET SPRITE PALETTE ...151       GFXCALL ..............151
  4197. GLOBAL ............... 46       GOSUB ................ 46
  4198. GOTO ................. 74       GR LOCATE ............ 73
  4199. GR WRITING ........... 70       HCOS ................. 70
  4200. HEX$ .................279       HIDE .................279
  4201. HOME ................. 92       HOT SPOT ............. 92
  4202. SCROLL ............... 98       HSIN ................. 98
  4203. HSLIDER ..............104       HTAN .................104
  4204. HUNT .................282       HZONE ................173
  4205. I BOB ................162       I SPRITE .............154
  4206. ICON BASE ............154       IF..THEN..[ELSE] ..... 75
  4207. IF..[ELSE]..ENDIF .... 76       INC .................. 39
  4208. INK .................. 61       INKEY$ ...............249
  4209. INPUT ................252       INPUT # ..............269
  4210. INPUT$ ...............271       INPUT$() .............250
  4211. INSTR ................ 56       INT ..................115
  4212. INTCALL ..............287       INVERSE ON/OFF ....... 88                  291
  4213. JDOWN ................169       JLEFT ................168
  4214. JOY ..................168       JRIGHT ...............168
  4215. JUP ..................168       KEY SHIFT ............250
  4216. KEY SPEED ............251       KEY STATE ............250
  4217. KILL .................265       LDIR .................274
  4218. LED ..................248       LEEK .................280
  4219. LEFT$ ................ 58       LEN .................. 58
  4220. LENGTH ............... 50       LIMIT BOB ............162
  4221. LIMIT MOUSE ..........167       LINE INPUT ...........253
  4222. LINE INPUT # .........253       LIST BANK ............ 49
  4223. LLIST ................274       LN ...................114
  4224. LOAD ................. 51       LOAD IFF .............124
  4225. LOCATE ............... 90       LOF ..................271
  4226. LOG ..................114       LOGBASE ..............136
  4227. LOGIC ................136       LOKE .................281
  4228. LOWER$ ............... 57       LPRINT ...............274
  4229. MAKE ICON MASK .......209       MAKE MASK ............172
  4230. MATCH ................ 60       MAX ..................116
  4231. MEMORIZE X/Y ......... 95       MENU$ ............212,215
  4232. MENU ACTIVE ..........229       MENU BAR .............228
  4233. MENU BASE ............231       MENU CALC ............222
  4234. MENU CALLED ..........226       MENU DEL .............221
  4235. MENU INACTIVE ........229       MENU ITEM MOVABLE ....230
  4236. MENU ITEM STATIC .....230       MENU KEY .............219
  4237. MENU LINE ............227       MENU LINKED ..........231
  4238. MENU MOUSE ...........232       MENU MOVABLE .........229
  4239. MENU ON/OFF ..213,220,221       MENU ONCE ............227
  4240. MENU SEPARATE ........231       MENU STATIC ..........230
  4241. MENU TLINE ...........228       MENU TO BANK .........221
  4242. MENU X ...............231       MENU Y ...............231
  4243. MID$ ................. 54       MIN ..................117
  4244. MKDIR ................265       MOUSE CLICK ..........166
  4245. MOUSE KEY ............166       MOUSE ZONE ...........173
  4246. MOVE FREEZE ..........205       MOVE ON/OFF ..........205
  4247. MOVE X ...............203       MOVE Y ...............204
  4248. MOVON ................205       MUSIC ................238
  4249. MUSIC OFF ............238       MUSIC STOP ...........238
  4250. MVOLUME ..............239       NO MASK ..............158
  4251. NOISE ................244       NOT ..................258
  4252. ON ERROR GOTO ........ 83       ON ERROR PROC ........ 84
  4253. ON MENU DEL ..........218       ON MENU GOSUB ........218
  4254. ON MENU GOTO .........218       ON MENU ON/OFF .......218
  4255. ON MENU PROC ......... 81       ON...GOSUB ........... 81
  4256. ON...GOTO ............ 81       ON...PROC ............ 81
  4257. OPEN IN ..............269       OPEN OUT .............269
  4258. OPEN PORT ............274       OPEN RANDOM ..........272
  4259. PACK .................277       PAINT ................ 67
  4260. PALETTE .............. 63       PAPER ................ 87
  4261. PAPER$ ............... 88       PARAM ................ 46
  4262. PARENT ...............264       PASTE BOB ............163
  4263. PASTE ICON ...........207       PEEK .................279
  4264. PEN .................. 87       PEN$ ................. 87
  4265. PHYBASE ..............135       PHYSIC ...............135
  4266. PI# ..................240       PLAY .................240
  4267. PLOAD ................285       PLOT ................. 64
  4268. POF ..................271       POINT ................ 64
  4269. POKE .................280       POLYGON .............. 68
  4270. POLYLINE ............. 65       POP .................. 75
  4271. POP PROC ............. 47       PORT .................275
  4272. PRG FIRST$ ........... 31       PRG NEXT$ ............ 31
  4273. PRINT # ..............269       PRINT / ? ............254
  4274. PRIORITY ON/OFF ......174       PROCEDURE ............ 42
  4275. PRUN ................. 31       PSEL$ ................ 32
  4276. PUT ..................273       PUT BLOCK ............210
  4277. PUT BOB ..............163       PUT CBLOCK ...........211
  4278. PUT KEY ..............252       RADIAN ...............111
  4279. RAIN .................141       RAINBOW ..............141
  4280. RANDOMIZE ............116       READ .................256
  4281. REM / ' ..............255       REMEMBER X/Y ......... 96
  4282. RENAME ...............265       REPEAT$ .............. 97
  4283. REPEAT...UNTIL ....... 78       RESERVE .............. 49
  4284. RESERVE ZONE .........172       RESET ZONE ...........174
  4285. RESTORE ..............257       RESUME ............... 85                  292
  4286. RETURN ............... 74       RIGHT$ ............... 54
  4287. RND ..................115       ROL ..................282
  4288. ROR ..................283       RUN ..................266
  4289. SAM BANK .............236       SAM LOOP .............237
  4290. SAM PLAY .............235       SAM RAW ..............236
  4291. SAMPLE ...............244       SAVE ................. 51
  4292. SAVE IFF .............124       SAY ..................247
  4293. SCAN$ ................ 29       SCANCODE .............249
  4294. SCIN .................130       SCREEN ...............129
  4295. SCREEN BASE ..........288       SCREEN CLONE .........127
  4296. SCREEN CLOSE .........121       SCREEN COLOUR ........130
  4297. SCREEN COPY ..........132       SCREEN DISPLAY .......125
  4298. SCREEN HEIGHT ........130       SCREEN HIDE ..........129
  4299. SCREEN OFFSET ........126       SCREEN OPEN ..........119
  4300. SCREEN SHOW ..........130       SCREEN SWAP ..........134
  4301. SCREEN TO BACK .......129       SCREEN TO FRONT ......129
  4302. SCREEN WIDTH .........130       SCROLL ...............134
  4303. SET BOB ..............157       SET BUFFER ........... 53
  4304. SET CURS ............. 95       SET DIR ..............264
  4305. SET ENVEL ............245       SET FONT .............108
  4306. SET INPUT ............270       STE LINE ............. 67
  4307. SET MENU .............232       SET PAINT ............ 70
  4308. SET PATTERN .......... 69       SET RAINBOW ..........139
  4309. SET SLIDER ...........104       SET SPRITE BUFFER ....151                  293
  4310. SET TAB .............. 97       SET TALK .............247
  4311. SET TEMPRAS .......... 71       SET TEXT .............108
  4312. SET WAVE .............241       SET ZONE .............172
  4313. SGN ..................115       SHADE ON/OFF ......... 88
  4314. SHARED ............... 45       SHIFT DOWN ...........139
  4315. SHIFT OFF ............139       SHIFT UP .............138
  4316. SHOOT ................233       SHOW .................165
  4317. SIN ..................111       SORT ................. 59
  4318. SPACE$ ............... 57       SPACK ................276
  4319. SPRITE ...............145       SPRITE BASE ..........288
  4320. SPRITE COL ...........169       SPRITE OFF ...........152
  4321. SPRITEBOB COL ........170       SPRITE UPDATE ........152
  4322. SQR ..................114       START ................ 50
  4323. STR$ ................. 59       STRING$ .............. 58
  4324. SWAP .................117       SYNCHRO ..............202
  4325. TAB$ ................. 97       TAN ..................112
  4326. TEMPO ................239       TEXT .................106
  4327. TEXT BASE ............109       TEXT LENGTH ..........109
  4328. TEXT STYLE ...........109       TIMER ................258
  4329. TITLE BOTTOM .........101       TITLE TOP ............101
  4330. TRUE .................258       UNDER ON/OFF ......... 89
  4331. UNPACK ...............277       UPDATE ...............175
  4332. UPDATE EVERY .........201       UPPER$ ............... 57
  4333. USING ................254       VAL .................. 59
  4334. VARPTR ...............281       VIEW .................121
  4335. VOICE ................239       VOLUME ...............235
  4336. VSCROLL .............. 99       VSLIDER ..............104
  4337. VUMETER ..............240       WAIT .................258
  4338. WAIT KEY .............259       WAIT VBL .............136
  4339. WAVE .................243       WHILE...WEND ......... 78
  4340. WIND CLOSE ...........102       WIND MOVE ............102
  4341. WIND SIZE ............103       WINDON ...............102
  4342. WINDOPEN ............. 99       WINDOW ...............102
  4343. WINDOW FONT ..........100       WINDSAVE .............100
  4344. WRITING .............. 89       X BOB ................162
  4345. X GRAPHIC ............ 92       X HARD ...............154
  4346. X MOUSE ..............167       X SCREEN .............153
  4347. X SPRITE .............152       XCURS ................ 94
  4348. XGR .................. 64       XTEXT ................ 91
  4349. Y BOB ................162       Y GRAPHIC ............ 92
  4350. Y HARD ...............154       Y MOUSE ..............167
  4351. Y SCREEN .............153       Y SPRITE .............153
  4352.